Skip to content

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>
Copy link
Member

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

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

Cool!

the :keyword:`import` statement occurs.
#. define a name or names in the current namespace for the scope where
the :keyword:`import` statement occurs, just as an assignment statement
would, including global, local, and nonlocal semantics.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this would be a little clearer?

Suggested change
would, including global, local, and nonlocal semantics.
would (including :keyword:`global` and :keyword:`nonlocal` semantics).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kovan
Copy link
Contributor Author

kovan commented Feb 10, 2026

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Feb 10, 2026

Thanks for making the requested changes!

@nedbat: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from nedbat February 10, 2026 15:42
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.

3 participants