Skip to content

Commit 1ccb1c4

Browse files
Special case __main__ in is_namespace() (#1579)
1 parent 2ff4800 commit 1ccb1c4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

astroid/interpreter/_import/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def is_namespace(modname: str) -> bool:
3434
working_modname, path=last_submodule_search_locations
3535
)
3636
except ValueError:
37-
# executed .pth files may not have __spec__
38-
return True
37+
# Assume it's a .pth file, unless it's __main__
38+
return modname != "__main__"
3939
except KeyError:
4040
# Intermediate steps might raise KeyErrors
4141
# https://github.com/python/cpython/issues/93334

tests/unittest_manager.py

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def test_submodule_homonym_with_non_module(self) -> None:
127127

128128
def test_module_is_not_namespace(self) -> None:
129129
self.assertFalse(util.is_namespace("tests.testdata.python3.data.all"))
130+
self.assertFalse(util.is_namespace("__main__"))
130131

131132
def test_implicit_namespace_package(self) -> None:
132133
data_dir = os.path.dirname(resources.find("data/namespace_pep_420"))

0 commit comments

Comments
 (0)