]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137337: Clarify import statement namespace binding (GH-144607)
authorKit Dallege <xaum.io@gmail.com>
Mon, 4 May 2026 14:45:00 +0000 (16:45 +0200)
committerGitHub <noreply@github.com>
Mon, 4 May 2026 14:45:00 +0000 (17:45 +0300)
It is not always in the local namespace.

Doc/reference/simple_stmts.rst

index 648e3a9bf54060be32d443ff4deced2334e77f10..f8e54aa0a108c8db20463ef5f7fc77cce2fbb116 100644 (file)
@@ -761,8 +761,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
@@ -807,7 +808,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