From 6a869f6e504189e638c6fb8c69e91f98a9f4f98b Mon Sep 17 00:00:00 2001 From: Vivek Dasari Date: Tue, 28 Mar 2023 22:21:21 +0000 Subject: [PATCH] bug: Check for relative import before looking up context.filename --- src/refac/visitors/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/refac/visitors/import_utils.py b/src/refac/visitors/import_utils.py index 4626783..6de4cef 100644 --- a/src/refac/visitors/import_utils.py +++ b/src/refac/visitors/import_utils.py @@ -182,7 +182,7 @@ def get_absolute_module_for_import( context: CodemodContext, node: cst.ImportFrom ) -> str: full_module_name = context.full_module_name - if context.filename.endswith("__init__.py") and node.relative: # type: ignore[union-attr] + if node.relative and context.filename.endswith("__init__.py"): # type: ignore[union-attr] # The module `a.b` can refer to either `a/b.py` or `a/b/__init__.py`. # To correctly disambiguate relative imports from __init__ files, we # append an `.__init__` module.