[modular] Do not track imports in functions (#36279)
* Add check * just check for function * Update examples
This commit is contained in:
@@ -649,9 +649,11 @@ class ModuleMapper(CSTVisitor, ABC):
|
||||
self.current_function = None
|
||||
|
||||
def visit_If(self, node):
|
||||
for stmt in node.body.body:
|
||||
if m.matches(stmt, m.SimpleStatementLine(body=[m.ImportFrom() | m.Import()])):
|
||||
self.imports.append(node)
|
||||
# If we are inside a function, do not add the import to the list of imports
|
||||
if self.current_function is None:
|
||||
for stmt in node.body.body:
|
||||
if m.matches(stmt, m.SimpleStatementLine(body=[m.ImportFrom() | m.Import()])):
|
||||
self.imports.append(node)
|
||||
|
||||
def visit_ClassDef(self, node: ClassDef) -> None:
|
||||
"""Record class nodes to create their dependencies at the end."""
|
||||
|
||||
Reference in New Issue
Block a user