Merge #1343: Speed up _collect_numerical_imports by 159%
This commit is contained in:
commit
60bd77675d
1 changed files with 5 additions and 1 deletions
|
|
@ -1429,7 +1429,9 @@ def _collect_numerical_imports(tree: ast.Module) -> tuple[set[str], set[str]]:
|
|||
numerical_names: set[str] = set()
|
||||
modules_used: set[str] = set()
|
||||
|
||||
for node in ast.walk(tree):
|
||||
stack: list[ast.AST] = [tree]
|
||||
while stack:
|
||||
node = stack.pop()
|
||||
if isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
# import numpy or import numpy as np
|
||||
|
|
@ -1451,6 +1453,8 @@ def _collect_numerical_imports(tree: ast.Module) -> tuple[set[str], set[str]]:
|
|||
name = alias.asname if alias.asname else alias.name
|
||||
numerical_names.add(name)
|
||||
modules_used.add(module_root)
|
||||
else:
|
||||
stack.extend(ast.iter_child_nodes(node))
|
||||
|
||||
return numerical_names, modules_used
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue