gh-137337: Clarify import statement namespace binding (GH-144607) · python/cpython@b8ebd07

GitHub

@@ -761,8 +761,9 @@ The basic import statement (no :keyword:`from` clause) is executed in two

761761steps:

762762763763#. 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).

766767767768When the statement contains multiple clauses (separated by

768769commas) 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