Skip to content

Commit ed4d4ac

Browse files
handle name.name imports like urllib.parse
1 parent ba5fdd8 commit ed4d4ac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

codeflash/code_utils/code_replacer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ def __init__(self) -> None:
381381
# Set of fully-qualified imports like "utils.helpers.extract_path"
382382
self.imported_names: set[str] = set()
383383

384+
def get_full_name(self, expr: cst.BaseExpression) -> str:
385+
if isinstance(expr, cst.Name):
386+
return expr.value
387+
if isinstance(expr, cst.Attribute):
388+
return f"{self.get_full_name(expr.value)}.{expr.attr.value}"
389+
return ""
390+
384391
def visit_ImportFrom(self, node: cst.ImportFrom) -> None:
385392
# Get the full module path like "utils.helpers"
386393
module = ("." * node.relative if node.relative else "") + (
@@ -399,7 +406,7 @@ def visit_ImportFrom(self, node: cst.ImportFrom) -> None:
399406
def visit_Import(self, node: cst.Import) -> None:
400407
for name in node.names:
401408
if isinstance(name, cst.ImportAlias):
402-
full_module_path = name.name.value # e.g., "utils.helpers"
409+
full_module_path = self.get_full_name(name.name)
403410
self.imported_names.add(full_module_path)
404411

405412

0 commit comments

Comments
 (0)