Skip to content

Commit

Permalink
fixup path comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Aug 28, 2022
1 parent 4c60c9d commit 22ce69e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
9 changes: 7 additions & 2 deletions astroid/interpreter/_import/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

@lru_cache(maxsize=4096)
def is_namespace(modname: str) -> bool:
from astroid.modutils import EXT_LIB_DIRS # pylint: disable=import-outside-toplevel
from astroid.modutils import ( # pylint: disable=import-outside-toplevel
EXT_LIB_DIRS,
STD_LIB_DIRS,
)

STD_AND_EXT_LIB_DIRS = STD_LIB_DIRS.union(EXT_LIB_DIRS)

if modname in sys.builtin_module_names:
return False
Expand Down Expand Up @@ -75,7 +80,7 @@ def is_namespace(modname: str) -> bool:
# Update last_submodule_search_locations
if found_spec and found_spec.submodule_search_locations:
if any(
location in EXT_LIB_DIRS
any(location.startswith(lib_dir) for lib_dir in STD_AND_EXT_LIB_DIRS)
for location in found_spec.submodule_search_locations
):
return False
Expand Down
14 changes: 0 additions & 14 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,10 @@ def test_submodule_homonym_with_non_module(self) -> None:
)

def test_module_is_not_namespace(self) -> None:
def debug_result():
import sysconfig
from importlib.util import _find_spec_from_path

tested = list(EXT_LIB_DIRS)[0].rsplit("/", maxsplit=1)[-1]
spec = _find_spec_from_path(tested)
return (
f"SYCONFIG PATHS: {sysconfig.get_paths()}\n"
f"EXT_LIB_DIRS: {EXT_LIB_DIRS}\n"
f"TESTED: {tested}\n"
f"SPEC VARS: {vars(spec)}"
)

self.assertFalse(util.is_namespace("tests.testdata.python3.data.all"))
self.assertFalse(util.is_namespace("__main__"))
self.assertFalse(
util.is_namespace(list(EXT_LIB_DIRS)[0].rsplit("/", maxsplit=1)[-1]),
debug_result(),
)
self.assertFalse(util.is_namespace("importlib._bootstrap"))

Expand Down

0 comments on commit 22ce69e

Please sign in to comment.