Skip to content

Commit b8ebd07

Browse files
author
Kit Dallege
authored
gh-137337: Clarify import statement namespace binding (GH-144607)
It is not always in the local namespace.
1 parent 1e21cf6 commit b8ebd07

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
@@ -761,8 +761,9 @@ The basic import statement (no :keyword:`from` clause) is executed in two
761761
steps:
762762

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

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

0 commit comments

Comments
 (0)