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

bpo-31799: Make module.__spec__ more discoverable #4010

Merged
merged 2 commits into from Oct 17, 2017

Conversation

warsaw
Copy link
Member

@warsaw warsaw commented Oct 16, 2017

This should be backported to Python 3.6

https://bugs.python.org/issue31799

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__``.
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Member Author

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.

@warsaw warsaw merged commit 191e313 into python:master Oct 17, 2017
@miss-islington
Copy link
Contributor

Thanks @warsaw for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 17, 2017
bpo-31799: Make module.__spec__ more discoverable
(cherry picked from commit 191e313)
@bedevere-bot
Copy link

GH-4021 is a backport of this pull request to the 3.6 branch.

warsaw pushed a commit that referenced this pull request Oct 17, 2017
)

bpo-31799: Make module.__spec__ more discoverable
(cherry picked from commit 191e313)
@warsaw warsaw deleted the bpo31799 branch October 17, 2017 20:00
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.

None yet

6 participants