Skip to content

gh-137337: Clarify import statement namespace binding#144607

Open
kovan wants to merge 1 commit intopython:mainfrom
kovan:gh-137337-import-namespace
Open

gh-137337: Clarify import statement namespace binding#144607
kovan wants to merge 1 commit intopython:mainfrom
kovan:gh-137337-import-namespace

Conversation

@kovan
Copy link
Contributor

@kovan kovan commented Feb 8, 2026

Summary

The import statement documentation says names are defined "in the local namespace," which is inaccurate when the imported name has been declared global or nonlocal:

x = None
def f():
    global x
    import os as x  # Assigns to global namespace, not local

Updates two places in Doc/reference/simple_stmts.rst:

  • The basic import description (step 2): "local namespace" -> "current namespace... just as an assignment statement would, including global, local, and nonlocal semantics"
  • The from ... import description (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 check passes
  • make -C Doc html passes (no warnings)

🤖 Generated with Claude Code


📚 Documentation preview 📚: https://cpython-previews--144607.org.readthedocs.build/

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants