Skip to content

Commit

Permalink
Special case __main__ in is_namespace() (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored May 31, 2022
1 parent 2ff4800 commit 1ccb1c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions astroid/interpreter/_import/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def is_namespace(modname: str) -> bool:
working_modname, path=last_submodule_search_locations
)
except ValueError:
# executed .pth files may not have __spec__
return True
# Assume it's a .pth file, unless it's __main__
return modname != "__main__"
except KeyError:
# Intermediate steps might raise KeyErrors
# https://github.com/python/cpython/issues/93334
Expand Down
1 change: 1 addition & 0 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_submodule_homonym_with_non_module(self) -> None:

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

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

0 comments on commit 1ccb1c4

Please sign in to comment.