Skip to content

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.

@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.

Copy link
Member

Choose a reason for hiding this comment

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

I agree.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe versionchanged? You can say something like, prior to 3.15, this class was exposed as the module private _NamespacePath class. With 3.15 and beyond, the class has been publicly exposed as NamespacePath.

Copy link
Member Author

Choose a reason for hiding this comment

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

The attribute is set on importlib._bootstrap_external, which is a private module, so I lean towards versionadded.

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).

Copy link
Member

Choose a reason for hiding this comment

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

Who's the backwards-compatibility for? People poking at private attributes in private modules?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it hurts, but I also don't think it's necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Well... considering it has been designed to support backwards compatibility, I thought it was worth the deprecation warning so that we can eventually remove it. But that could make the code a bit more complex (as we would need some logic in the module's __getattr__), so I'm also fine with leaving it as is.


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.

Copy link
Member Author

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).

I've rewritten the docs to include this.

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

Using NamespacePath's mutability at runtime is something that requires folks to be familiar with the source, so I don't think we really need to document that.

The main improvement I want to get from the PR is the ability to isinstance(path, NamespacePath) safely.

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.

Similarly, I don't really think that is necessary given the advanced nature of the topic.

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.

Really just a very minor doc change is needed to add a note as to when the class was publicly exposed.

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.

Who's the backwards-compatibility for? People poking at private attributes in private modules?


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.

I agree.

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.

I don't think it hurts, but I also don't think it's necessary.

@brettcannon brettcannon self-assigned this Sep 5, 2025
@FFY00 FFY00 requested a review from brettcannon October 9, 2025 22:22
Copy link
Member

@warsaw warsaw left a comment

Choose a reason for hiding this comment

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

Approved, with some suggestions and comments. Thanks for finally fixing this wart!

The *path* argument is the initial path value.

The *path_finder* argument is the callable used to recompute the path value.
It has the same signature as :meth:`MetaPathFinder.find_spec`.
Copy link
Member

Choose a reason for hiding this comment

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

It's a little hard to tell from context, but which "it" is "It" referring to? I'm not sure if this is part of the path_finder paragraph or a separate paragraph.

Copy link
Member Author

Choose a reason for hiding this comment

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

It refers to path_finder, I'll rewrite it as "The callable has the same signature as (...)"


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.

Maybe versionchanged? You can say something like, prior to 3.15, this class was exposed as the module private _NamespacePath class. With 3.15 and beyond, the class has been publicly exposed as NamespacePath.

FFY00 and others added 2 commits October 10, 2025 06:39
Signed-off-by: Filipe Laíns <[email protected]>
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