Skip to content

Commit b803521

Browse files
kovanclaude
andcommitted
gh-137337: Clarify import statement namespace binding
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>
1 parent cfeede8 commit b803521

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,9 @@ The basic import statement (no :keyword:`from` clause) is executed in two
760760
steps:
761761

762762
#. find a module, loading and initializing it if necessary
763-
#. define a name or names in the local namespace for the scope where
764-
the :keyword:`import` statement occurs.
763+
#. define a name or names in the current namespace for the scope where
764+
the :keyword:`import` statement occurs, just as an assignment statement
765+
would, including global, local, and nonlocal semantics.
765766

766767
When the statement contains multiple clauses (separated by
767768
commas) the two steps are carried out separately for each clause, just
@@ -806,7 +807,7 @@ The :keyword:`from` form uses a slightly more complex process:
806807
#. if not, attempt to import a submodule with that name and then
807808
check the imported module again for that attribute
808809
#. if the attribute is not found, :exc:`ImportError` is raised.
809-
#. otherwise, a reference to that value is stored in the local namespace,
810+
#. otherwise, a reference to that value is stored in the current namespace,
810811
using the name in the :keyword:`!as` clause if it is present,
811812
otherwise using the attribute name
812813

0 commit comments

Comments
 (0)