Skip to content

Commit a2c78d4

Browse files
committed
Clarifying nonlocal documtation: SyntaxError is thrown if nearest enclosing scope is global
1 parent cf34b77 commit a2c78d4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/reference/simple_stmts.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,9 @@ The :keyword:`nonlocal` statement causes the listed identifiers to refer to
10111011
previously bound variables in the nearest enclosing scope excluding globals.
10121012
This is important because the default behavior for binding is to search the
10131013
local namespace first. The statement allows encapsulated code to rebind
1014-
variables outside of the local scope besides the global (module) scope.
1014+
variables outside of the local scope besides the global scope. A :exc:`SyntaxError`
1015+
will be raised if the nearest enclosing scope is the global (module) scope.
1016+
10151017

10161018
Names listed in a :keyword:`nonlocal` statement, unlike those listed in a
10171019
:keyword:`global` statement, must refer to pre-existing bindings in an

0 commit comments

Comments
 (0)