X Tutup
The Wayback Machine - https://web.archive.org/web/20221223164612/https://github.com/python/cpython/pull/92164
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

gh-87304: Summary of the changes made: added detailed explanation for import #92164

Merged
merged 3 commits into from May 3, 2022

Conversation

robert861212
Copy link
Contributor

@robert861212 robert861212 commented May 2, 2022

Explained how import works in better details in the doc. Mentored by Toshio Kuratomi.

#87304

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented May 2, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot
Copy link

bedevere-bot commented May 2, 2022

Every change to Python requires a NEWS entry.

Please, add it using the blurb_it Web app or the blurb command-line tool.

@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels May 2, 2022
@@ -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
Copy link
Member

@JelleZijlstra JelleZijlstra May 2, 2022

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

@robert861212 robert861212 requested a review from JelleZijlstra May 2, 2022
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
Copy link
Member

@JelleZijlstra JelleZijlstra May 2, 2022

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

@robert861212 robert861212 May 3, 2022

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?

Copy link
Member

@JelleZijlstra JelleZijlstra May 3, 2022

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.

Copy link
Contributor Author

@robert861212 robert861212 May 3, 2022

Choose a reason for hiding this comment

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

got it! refactored

@JelleZijlstra JelleZijlstra self-assigned this May 2, 2022
@robert861212 robert861212 requested a review from JelleZijlstra May 3, 2022
@JelleZijlstra JelleZijlstra merged commit ee2205b into python:main May 3, 2022
13 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented May 3, 2022

Thanks @robert861212 for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒🤖

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 3, 2022

Thanks for your contribution!

@bedevere-bot
Copy link

bedevere-bot commented May 3, 2022

GH-92272 is a backport of this pull request to the 3.10 branch.

@bedevere-bot
Copy link

bedevere-bot commented May 3, 2022

GH-92273 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 3, 2022
…ythonGH-92164)

(cherry picked from commit ee2205b)

Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
miss-islington added a commit that referenced this pull request May 3, 2022
(cherry picked from commit ee2205b)

Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
miss-islington added a commit that referenced this pull request May 3, 2022
(cherry picked from commit ee2205b)

Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…ythonGH-92164)

(cherry picked from commit ee2205b)

Co-authored-by: Robert Yang <35813883+robert861212@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants
X Tutup