-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-87304: Summary of the changes made: added detailed explanation for import #92164
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
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
Doc/reference/simple_stmts.rst
Outdated
@@ -806,6 +806,14 @@ Examples:: | |||
from foo.bar import baz # foo.bar.baz imported and bound as baz | |||
from foo import attr # foo imported and foo.attr bound as attr | |||
|
|||
Note: When a submodule is imported, all parent modules are imported and may |
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 this is too much detail. Above there is already a reference to https://docs.python.org/3/reference/import.html#searching, which explains this behavior. I would just change the comments in the above block to say "foo, foo.bar, and foo.bar.baz imported".
Doc/reference/simple_stmts.rst
Outdated
import foo.bar.baz # foo, foo.bar, and foo.bar.baz imported, foo bound locally | ||
import foo.bar.baz as fbb # foo, foo.bar, and foo.bar.baz imported, foo.bar.baz bound as fbb | ||
from foo.bar import baz # foo, foo.bar, and foo.bar.baz imported, foo.bar.baz bound as baz | ||
from foo import attr # foo and foo.attr imported and foo.attr bound as attr |
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.
from foo import attr # foo and foo.attr imported and foo.attr bound as attr | |
from foo import attr # foo imported and foo.attr bound as attr |
I think the intent here is that foo.attr
is a regular attribute of foo
, not a submodule.
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.
Would foo.attr still be technically imported?
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.
No, see line 793 above. If the attr already exists, it doesn't try to import it.
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.
got it! refactored
Thanks @robert861212 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Thanks for your contribution! |
GH-92272 is a backport of this pull request to the 3.10 branch. |
GH-92273 is a backport of this pull request to the 3.9 branch. |
…ythonGH-92164) (cherry picked from commit ee2205b) Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
…ythonGH-92164) (cherry picked from commit ee2205b) Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
Explained how import works in better details in the doc. Mentored by Toshio Kuratomi.
#87304