From b803521643389d114aad39621e8a5b9ff7637955 Mon Sep 17 00:00:00 2001 From: kovan Date: Sun, 8 Feb 2026 21:44:57 +0100 Subject: [PATCH 1/2] 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 --- Doc/reference/simple_stmts.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index 36b30c9b16b0db..251b717e183b5c 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -760,8 +760,9 @@ The basic import statement (no :keyword:`from` clause) is executed in two steps: #. find a module, loading and initializing it if necessary -#. define a name or names in the local namespace for the scope where - 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. When the statement contains multiple clauses (separated by 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: #. if not, attempt to import a submodule with that name and then check the imported module again for that attribute #. if the attribute is not found, :exc:`ImportError` is raised. - #. otherwise, a reference to that value is stored in the local namespace, + #. otherwise, a reference to that value is stored in the current namespace, using the name in the :keyword:`!as` clause if it is present, otherwise using the attribute name From 06eef10556a13c0a1219bd73b068b26545e8ae3d Mon Sep 17 00:00:00 2001 From: kovan Date: Tue, 10 Feb 2026 16:37:55 +0100 Subject: [PATCH 2/2] gh-137337: Use :keyword: cross-references for global/nonlocal Co-Authored-By: Claude Opus 4.6 --- Doc/reference/simple_stmts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index 251b717e183b5c..c990f89bfc2da3 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -762,7 +762,7 @@ steps: #. find a module, loading and initializing it if necessary #. 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. + would (including :keyword:`global` and :keyword:`nonlocal` semantics). When the statement contains multiple clauses (separated by commas) the two steps are carried out separately for each clause, just