Skip to content

GH-119668: expose importlib.machinery.NamespacePath #119669

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

FFY00
Copy link
Member

@FFY00 FFY00 commented May 28, 2024

FFY00 and others added 3 commits May 28, 2024 17:14
Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

See the comments that @picnixz left.

@bedevere-app
Copy link

bedevere-app bot commented Jul 10, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@picnixz
Copy link
Member

picnixz commented Jul 22, 2024

The docs failure is related to the fact that you did not yet merge main into your branch. Since I don't like updating branches of people, I'll let you do it yourself.

@@ -14,6 +14,7 @@
from ._bootstrap_external import ExtensionFileLoader
from ._bootstrap_external import AppleFrameworkLoader
from ._bootstrap_external import NamespaceLoader
from ._bootstrap_external import NamespacePath
Copy link
Member

Choose a reason for hiding this comment

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

Contrary to the title and what's new entry, this doesn't expose importlib.NamespacePath, but importlib.machinery.NamespacePath:

>>> from importlib import NamespacePath
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    from importlib import NamespacePath
ImportError: cannot import name 'NamespacePath' from 'importlib' (...)
>>> from importlib.machinery import NamespacePath
>>> 

Aside from what you intended, I'm not sure that this isn't actually better. importlib.NamespacePath seems a little odd to me, and while something like importlib.abc might be better, but this isn't really an ABC. So importlib.machinery.NamespacePath seems fine. Care to chime in, @brettcannon ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, sorry! I am okay with either namespace. From the lack of feedback, I think it should be okay to proceed with importlib.machinery.NamespacePath.

@FFY00 FFY00 changed the title GH-119668: expose importlib.NamespacePath GH-119668: expose importlib.machinery.NamespacePath Nov 17, 2024
@FFY00 FFY00 requested a review from brettcannon November 17, 2024 04:01
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the previous review but I think the docs should explain the public API more in details and possibly have an example. I'm reviewing on my phone so sorry for the typos (and the lack of explicit suggestions)


For top-level modules, the parent module's path is :data:`sys.path`.


Copy link
Member

Choose a reason for hiding this comment

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

Can we use .. versionadded:: next + what's new entry? While this only exposes a private class, I think users should be notified more than just with a blurb.

@@ -1147,12 +1150,15 @@ def append(self, item):
self._path.append(item)


_NamespacePath = NamespacePath # for backwards compatibility
Copy link
Member

Choose a reason for hiding this comment

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

Should we make it a deprecated alias? (and emit a warning if we were to access the private name? that could help transition from the private to the public name).


It uses the module *name* to find its parent module, and from there it looks
up the parent's :attr:`module.__path__`. When this changes, the module's own
path is recomputed, using *path_finder*. The initial value is set to *path*.
Copy link
Member

Choose a reason for hiding this comment

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

Can we perhaps mention the type of the path finder? (namely using some class Sphinx directive).

Btw, when you say that the initial value is set to path it seems that you are talking about the initial value of the path finder.

In addition, maybe mention that invalidating the caches forces the path to be recomputed (it might not necessarily be the case that the module parent's path has changed).

Finally, could you document the public methods of this new class? For instance there is no insert() method nor remove() as for lists.

I think an example of how to use it could be useful though I don't know whether we want to burden the docs even more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants