gh-137337: Clarify import statement namespace binding#144607
Open
kovan wants to merge 1 commit intopython:mainfrom
Open
gh-137337: Clarify import statement namespace binding#144607kovan wants to merge 1 commit intopython:mainfrom
kovan wants to merge 1 commit intopython:mainfrom
Conversation
The import statement docs said names are defined "in the local namespace", which is inaccurate when the name has been declared global or nonlocal. Update to say "current namespace... just as an assignment statement would", per discussion with nedbat, serhiy-storchaka, and terryjreedy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nedbat
approved these changes
Feb 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The import statement documentation says names are defined "in the local namespace," which is inaccurate when the imported name has been declared
globalornonlocal:Updates two places in
Doc/reference/simple_stmts.rst:importdescription (step 2): "local namespace" -> "current namespace... just as an assignment statement would, including global, local, and nonlocal semantics"from ... importdescription (step 2.d): "local namespace" -> "current namespace"This follows the wording proposed by @nedbat and discussed with @serhiy-storchaka and @terryjreedy in the issue thread.
Test plan
make -C Doc checkpassesmake -C Doc htmlpasses (no warnings)🤖 Generated with Claude Code
importstatement should include binding toglobalandnonlocalnamespaces #137337📚 Documentation preview 📚: https://cpython-previews--144607.org.readthedocs.build/