Skip to content

Commit f29824a

Browse files
committed
pre-commit cleanup
1 parent 0e0f916 commit f29824a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

codeflash/discovery/discover_unit_tests.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,31 +167,34 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
167167
if alias.name == "*":
168168
# Star imports - we can't know what's imported, so be conservative
169169
self.imported_names.add("*")
170-
else:
171-
imported_name = alias.asname if alias.asname else alias.name
170+
elif imported_name := (alias.asname if alias.asname else alias.name):
172171
self.imported_names.add(imported_name)
173-
174-
# Check if this import matches any target function
175172
if alias.name in self.function_names_to_find:
176173
self.found_target_functions.add(alias.name)
177174
self.generic_visit(node)
178175

179176
def visit_Call(self, node: ast.Call) -> None:
180177
"""Handle dynamic imports like importlib.import_module() or __import__()."""
181-
if isinstance(node.func, ast.Name) and node.func.id == "__import__" and node.args:
178+
if (
179+
isinstance(node.func, ast.Name)
180+
and node.func.id == "__import__"
181+
and node.args
182+
and isinstance(node.args[0], ast.Constant)
183+
and isinstance(node.args[0].value, str)
184+
):
182185
# __import__("module_name")
183-
if isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str):
184-
self.imported_modules.add(node.args[0].value)
186+
self.imported_modules.add(node.args[0].value)
185187
elif (
186188
isinstance(node.func, ast.Attribute)
187189
and isinstance(node.func.value, ast.Name)
188190
and node.func.value.id == "importlib"
189191
and node.func.attr == "import_module"
190192
and node.args
193+
and isinstance(node.args[0], ast.Constant)
194+
and isinstance(node.args[0].value, str)
191195
):
192196
# importlib.import_module("module_name")
193-
if isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str):
194-
self.imported_modules.add(node.args[0].value)
197+
self.imported_modules.add(node.args[0].value)
195198
self.generic_visit(node)
196199

197200
def visit_Name(self, node: ast.Name) -> None:

0 commit comments

Comments
 (0)