]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-137337: Clarify import statement namespace binding (GH-144607) (GH-149370)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 4 May 2026 14:52:02 +0000 (16:52 +0200)
committerGitHub <noreply@github.com>
Mon, 4 May 2026 14:52:02 +0000 (14:52 +0000)
It is not always in the local namespace.
(cherry picked from commit b8ebd078f90007d48fcab85effadb33769cd080c)

Co-authored-by: Kit Dallege <xaum.io@gmail.com>
Doc/reference/simple_stmts.rst

index 8ed456a731b101e45545f18cebfb2784bee3138a..3a7d67396bc866f82df3a3ee3443ea95c0503d65 100644 (file)
@@ -763,8 +763,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 :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
@@ -809,7 +810,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