File tree Expand file tree Collapse file tree 2 files changed +7
-16
lines changed
astroid/interpreter/_import Expand file tree Collapse file tree 2 files changed +7
-16
lines changed Original file line number Diff line number Diff line change 1515
1616@lru_cache (maxsize = 4096 )
1717def is_namespace (modname : str ) -> bool :
18- from astroid .modutils import EXT_LIB_DIRS # pylint: disable=import-outside-toplevel
18+ from astroid .modutils import ( # pylint: disable=import-outside-toplevel
19+ EXT_LIB_DIRS ,
20+ STD_LIB_DIRS ,
21+ )
22+
23+ STD_AND_EXT_LIB_DIRS = STD_LIB_DIRS .union (EXT_LIB_DIRS )
1924
2025 if modname in sys .builtin_module_names :
2126 return False
@@ -75,7 +80,7 @@ def is_namespace(modname: str) -> bool:
7580 # Update last_submodule_search_locations
7681 if found_spec and found_spec .submodule_search_locations :
7782 if any (
78- location in EXT_LIB_DIRS
83+ any ( location . startswith ( lib_dir ) for lib_dir in STD_AND_EXT_LIB_DIRS )
7984 for location in found_spec .submodule_search_locations
8085 ):
8186 return False
Original file line number Diff line number Diff line change @@ -128,24 +128,10 @@ def test_submodule_homonym_with_non_module(self) -> None:
128128 )
129129
130130 def test_module_is_not_namespace (self ) -> None :
131- def debug_result ():
132- import sysconfig
133- from importlib .util import _find_spec_from_path
134-
135- tested = list (EXT_LIB_DIRS )[0 ].rsplit ("/" , maxsplit = 1 )[- 1 ]
136- spec = _find_spec_from_path (tested )
137- return (
138- f"SYCONFIG PATHS: { sysconfig .get_paths ()} \n "
139- f"EXT_LIB_DIRS: { EXT_LIB_DIRS } \n "
140- f"TESTED: { tested } \n "
141- f"SPEC VARS: { vars (spec )} "
142- )
143-
144131 self .assertFalse (util .is_namespace ("tests.testdata.python3.data.all" ))
145132 self .assertFalse (util .is_namespace ("__main__" ))
146133 self .assertFalse (
147134 util .is_namespace (list (EXT_LIB_DIRS )[0 ].rsplit ("/" , maxsplit = 1 )[- 1 ]),
148- debug_result (),
149135 )
150136 self .assertFalse (util .is_namespace ("importlib._bootstrap" ))
151137
You can’t perform that action at this time.
0 commit comments