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

Provide first component of dotted path to namespace searches #1575

Merged
merged 8 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions astroid/interpreter/_import/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def is_namespace(modname: str) -> bool:
except ValueError:
# executed .pth files may not have __spec__
return True
except KeyError:
# https:/python/cpython/issues/93334
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
return False
last_parent = working_modname

if found_spec is None:
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions tests/testdata/python3/data/parent_of_homonym/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This submodule should have the same name as a directory in the root of the project that
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we should really move these files to a tests/data directory instead of this one...

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is definitely some cleanup to do in the tests directory, there is also the issue of legacy functional tests. https:/PyCQA/pylint/blob/main/tests/test_func.py#L117 nvm it's in pylint

is _NOT_ a python module. For this reason, it's currently called "doc".
Empty file.
5 changes: 5 additions & 0 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def test_identify_old_namespace_package_protocol(self) -> None:
util.is_namespace("tests.testdata.python3.data.path_pkg_resources_1")
)

def test_homonoym_with_non_module(self) -> None:
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
self.assertFalse(
util.is_namespace("tests.testdata.python3.data.parent_of_homonym.doc")
)

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