mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] Clarifying nonlocal doc: SyntaxError is raised if nearest enclosing scope is global (GH-114009) (#118128)
Clarifying nonlocal doc: SyntaxError is raised if nearest enclosing scope is global (GH-114009)
(cherry picked from commit 1558d99316
)
Co-authored-by: Quazi Irfan <quazirfan@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
23192aba20
commit
4d85f0ae76
1 changed files with 3 additions and 2 deletions
|
@ -139,8 +139,9 @@ namespace. Names are resolved in the top-level namespace by searching the
|
||||||
global namespace, i.e. the namespace of the module containing the code block,
|
global namespace, i.e. the namespace of the module containing the code block,
|
||||||
and the builtins namespace, the namespace of the module :mod:`builtins`. The
|
and the builtins namespace, the namespace of the module :mod:`builtins`. The
|
||||||
global namespace is searched first. If the names are not found there, the
|
global namespace is searched first. If the names are not found there, the
|
||||||
builtins namespace is searched. The :keyword:`!global` statement must precede
|
builtins namespace is searched next. If the names are also not found in the
|
||||||
all uses of the listed names.
|
builtins namespace, new variables are created in the global namespace.
|
||||||
|
The global statement must precede all uses of the listed names.
|
||||||
|
|
||||||
The :keyword:`global` statement has the same scope as a name binding operation
|
The :keyword:`global` statement has the same scope as a name binding operation
|
||||||
in the same block. If the nearest enclosing scope for a free variable contains
|
in the same block. If the nearest enclosing scope for a free variable contains
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue