Skip to content

Commit

Permalink
Do not reassign submodule_path parameters in method bodies
Browse files Browse the repository at this point in the history
This makes it easier to use less generic annotations with mypy.
  • Loading branch information
correctmost authored and DanielNoord committed Sep 5, 2024
1 parent 1495979 commit 71f5c0c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def find_module(
submodule_path: Sequence[str] | None,
) -> ModuleSpec | None:
if submodule_path is not None:
submodule_path = list(submodule_path)
search_paths = list(submodule_path)
elif modname in sys.builtin_module_names:
return ModuleSpec(
name=modname,
Expand All @@ -159,10 +159,10 @@ def find_module(
)
except ValueError:
pass
submodule_path = sys.path
search_paths = sys.path

suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
for entry in submodule_path:
for entry in search_paths:
package_directory = os.path.join(entry, modname)
for suffix in suffixes:
package_file_name = "__init__" + suffix
Expand Down Expand Up @@ -231,13 +231,12 @@ def find_module(
if processed:
modname = ".".join([*processed, modname])
if util.is_namespace(modname) and modname in sys.modules:
submodule_path = sys.modules[modname].__path__
return ModuleSpec(
name=modname,
location="",
origin="namespace",
type=ModuleType.PY_NAMESPACE,
submodule_search_locations=submodule_path,
submodule_search_locations=sys.modules[modname].__path__,
)
return None

Expand Down

0 comments on commit 71f5c0c

Please sign in to comment.