Skip to content

Commit 3868444

Browse files
miss-islingtonKit Dallege
andauthored
[3.13] gh-137337: Clarify import statement namespace binding (GH-144607) (GH-149370)
It is not always in the local namespace. (cherry picked from commit b8ebd07) Co-authored-by: Kit Dallege <xaum.io@gmail.com>
1 parent 6d6471b commit 3868444

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Doc/reference/simple_stmts.rst

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

765765
#. find a module, loading and initializing it if necessary
766-
#. define a name or names in the local namespace for the scope where
767-
the :keyword:`import` statement occurs.
766+
#. define a name or names in the current namespace for the scope where
767+
the :keyword:`import` statement occurs, just as an assignment statement
768+
would (including :keyword:`global` and :keyword:`nonlocal` semantics).
768769

769770
When the statement contains multiple clauses (separated by
770771
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:
809810
#. if not, attempt to import a submodule with that name and then
810811
check the imported module again for that attribute
811812
#. if the attribute is not found, :exc:`ImportError` is raised.
812-
#. otherwise, a reference to that value is stored in the local namespace,
813+
#. otherwise, a reference to that value is stored in the current namespace,
813814
using the name in the :keyword:`!as` clause if it is present,
814815
otherwise using the attribute name
815816

0 commit comments

Comments
 (0)