-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-31799: Make module.__spec__ more discoverable #4010
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
Conversation
Doc/library/importlib.rst
Outdated
typically exposed as the module's ``__spec__`` attribute. In the | ||
descriptions below, the parenthetical "dunder" version names the equivalent | ||
attribute available directly on the module object. | ||
E.g. ``module.__spec__.name == module.__name__``. |
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.
This isn't quite true, since some of the names are different.
PEP 451 has the equivalence table, but we should probably move that into the library reference somewhere: https://www.python.org/dev/peps/pep-0451/#attributes
(Perhaps here?)
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.
Then what exactly are those parenthetical names supposed to describe?
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.
Maybe @brettcannon can shed some light on what those parenthetical names are supposed to mean?
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.
https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec has the name equivalence in parentheses from dunder name to spec name.
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.
@brettcannon I think when you say "the name equivalence in parentheses from dunder name to spec name", you're agreeing with what I wrote in the doc change. But then I'm confused about what @ncoghlan is saying that "some of the names are different". It's true that the names in the spec are not the same as the dunder names on the module object, but that's not what I'm saying in the new docs. At least I'm trying to say what @brettcannon is saying. :) Is my wording too confusing?
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.
I think using the dunder
jargon is what confused me, when combined with the use of an example where they are the same. (The fact I was looking at the change in isolation without any of the attribute descriptions in front of me didn't help).
I'd find this clearer:
In the descriptions below, the name given in parentheses is the corresponding attribute available directly on the module object. These values are equivalent in most cases (e.g.
module.__file__ == module.__spec__.origin
), but may differ if the module attribute has been modified at runtime (e.g. when overriding__name__
or updating__path__
).
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.
Thanks @ncoghlan that was helpful clarification. I pushed an update to this section.
Thanks @warsaw for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
bpo-31799: Make module.__spec__ more discoverable (cherry picked from commit 191e313)
GH-4021 is a backport of this pull request to the 3.6 branch. |
This should be backported to Python 3.6
https://bugs.python.org/issue31799