https://github.com/python/cpython/commit/b05ee207513991541fe280e109a7aeb6eb6be9b6 commit: b05ee207513991541fe280e109a7aeb6eb6be9b6 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-05-04T14:52:50Z summary:
[3.14] gh-137337: Clarify import statement namespace binding (GH-144607) (GH-149369) It is not always in the local namespace. (cherry picked from commit b8ebd078f90007d48fcab85effadb33769cd080c) Co-authored-by: Kit Dallege <[email protected]> files: M Doc/reference/simple_stmts.rst diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index 36b30c9b16b0db..c990f89bfc2da3 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -760,8 +760,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 @@ -806,7 +807,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 _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
