Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case __main__ in is_namespace() #1579

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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