Skip to content

Commit ce0d32f

Browse files
authored
Merge pull request #218 from seddonym/optimize-is-external
Don't reinstantiate package_modules within each loop
2 parents 37eaec4 + 9148ccb commit ce0d32f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/grimp/application/usecases.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,17 @@ def _assemble_graph(
167167
imports_by_module: Dict[Module, Set[DirectImport]],
168168
) -> ImportGraph:
169169
graph: ImportGraph = settings.IMPORT_GRAPH_CLASS()
170+
171+
package_modules = {Module(found_package.name) for found_package in found_packages}
172+
170173
for module, direct_imports in imports_by_module.items():
171174
graph.add_module(module.name)
172175
for direct_import in direct_imports:
173176
# Before we add the import, check to see if the imported module is in fact an
174177
# external module, and if so, tell the graph that it is a squashed module.
175178
graph.add_module(
176179
direct_import.imported.name,
177-
is_squashed=_is_external(direct_import.imported, found_packages),
180+
is_squashed=_is_external(direct_import.imported, package_modules),
178181
)
179182

180183
graph.add_import(
@@ -186,9 +189,7 @@ def _assemble_graph(
186189
return graph
187190

188191

189-
def _is_external(module: Module, found_packages: Set[FoundPackage]) -> bool:
190-
package_modules = [Module(found_package.name) for found_package in found_packages]
191-
192+
def _is_external(module: Module, package_modules: Set[Module]) -> bool:
192193
return not any(
193194
module.is_descendant_of(package_module) or module == package_module
194195
for package_module in package_modules

0 commit comments

Comments
 (0)