Skip to content

Commit 0c62da9

Browse files
committed
Update global and nonlocal section 4.2.2
1 parent cf34b77 commit 0c62da9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Doc/reference/executionmodel.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ namespace. Names are resolved in the top-level namespace by searching the
139139
global namespace, i.e. the namespace of the module containing the code block,
140140
and the builtins namespace, the namespace of the module :mod:`builtins`. The
141141
global namespace is searched first. If the names are not found there, the
142-
builtins namespace is searched. The :keyword:`!global` statement must precede
143-
all uses of the listed names.
142+
builtins namespace is searched. If the name is also not in the builtins namespace,
143+
a new variable is created in the global namespace. The :keyword:`!global` statement
144+
must precede all uses of the listed names.
144145

145146
The :keyword:`global` statement has the same scope as a name binding operation
146147
in the same block. If the nearest enclosing scope for a free variable contains
@@ -151,7 +152,8 @@ a global statement, the free variable is treated as a global.
151152
The :keyword:`nonlocal` statement causes corresponding names to refer
152153
to previously bound variables in the nearest enclosing function scope.
153154
:exc:`SyntaxError` is raised at compile time if the given name does not
154-
exist in any enclosing function scope. :ref:`Type parameters <type-params>`
155+
exist in any enclosing function scope, or if the nearest enclosing scope is
156+
the global (module) scope. :ref:`Type parameters <type-params>`
155157
cannot be rebound with the :keyword:`!nonlocal` statement.
156158

157159
.. index:: pair: module; __main__

0 commit comments

Comments
 (0)