-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
bpo-32303: Consistency fixes for namespace loaders #5481
Conversation
Also, repair a couple of tests.
Lib/test/test_importlib/util.py
Outdated
@@ -441,7 +441,7 @@ def contents(self): | |||
origin='does-not-exist', | |||
is_package=is_package) | |||
module.__spec__ = spec | |||
module.__loader__ = loader | |||
module.__loader__ = module.__loader__ = loader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason to double-assign the same attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, good catch! I thought I needed that in a previous commit, but I don't, so removed!
Doc/library/importlib.rst
Outdated
@@ -1291,7 +1291,7 @@ find and load modules. | |||
Name of the place from which the module is loaded, e.g. "builtin" for | |||
built-in modules and the filename for modules loaded from source. | |||
Normally "origin" should be set, but it may be ``None`` (the default) | |||
which indicates it is unspecified. | |||
which indicates it is unspecified (e.g. for namespace pacakges). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/pacakges/packages/
@warsaw: Please replace |
Thanks @warsaw for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
GH-5498 is a backport of this pull request to the 3.7 branch. |
* Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages. * Make sure ``__spec__.origin` matches ``__file__`` for namespace packages. https://bugs.python.org/issue32303 https://bugs.python.org/issue32305 (cherry picked from commit bbbcf86) Co-authored-by: Barry Warsaw <barry@python.org>
Sorry, @warsaw, I could not cleanly backport this to |
* Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages. * Make sure ``__spec__.origin` matches ``__file__`` for namespace packages. https://bugs.python.org/issue32303 https://bugs.python.org/issue32305 (cherry picked from commit bbbcf86) Co-authored-by: Barry Warsaw <barry@python.org>
* Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages. * Make sure ``__spec__.origin` matches ``__file__`` for namespace packages. https://bugs.python.org/issue32303 https://bugs.python.org/issue32305. (cherry picked from commit bbbcf86) Co-authored-by: Barry Warsaw <barry@python.org>
GH-5504 is a backport of this pull request to the 3.6 branch. |
…5504) * Make sure ``__spec__.loader`` matches ``__loader__`` for namespace packages. * Make sure ``__spec__.origin` matches ``__file__`` for namespace packages. https://bugs.python.org/issue32303 https://bugs.python.org/issue32305. (cherry picked from commit bbbcf86) Co-authored-by: Barry Warsaw <barry@python.org>
…thonGH-5481) (python#5504)" This reverts commit a71397f.
…pace package ModuleSpec.origin was changed in python/cpython#5481 to be None for namespace packages.
This branch actually fixes two inconsistencies for namespace package loaders.
__loader__
and__spec__.loader
. This inconsistency leads to namespace packages having a valid__loader__
butNone
for__spec__.loader
. This branch fixes it by ensuring that the two attributes start out the same. (As always, a user could change one or the other, and no attempt is made by Python to keep them in sync.)__file__
and__spec__.origin
. Here, namespace packages have a__spec__.origin
that is the literal string"namespace"
, and they do not have a__file__
attribute. Not only is this inconsistent, I believe it violates the documentation. The fix here is to set both__spec__.origin
and__file__
toNone
for namespace packages.I suppose it's possible that this will break existing code, but I'd argue that because current behavior runs counter to the documentation and makes no sense given the inconsistencies, it is better to fix them. I propose this change be applied to 3.7 and 3.6, although if you, my friendly reviewer, disagrees about 3.6, we can talk about it!
This isn't a security issue to back porting to 3.5 is off the table.
https://bugs.python.org/issue32303