Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@
...
SyntaxError: name 'x' is used prior to nonlocal declaration

>>> def f():
... x = 1
... def g():
... x = 2
... nonlocal x
Traceback (most recent call last):
...
SyntaxError: name 'x' is assigned to before nonlocal declaration

>>> def f(x):
... nonlocal x
Traceback (most recent call last):
Expand All @@ -409,24 +418,7 @@
...
SyntaxError: nonlocal declaration not allowed at module level

TODO(jhylton): Figure out how to test SyntaxWarning with doctest.

## >>> def f(x):
## ... def f():
## ... print(x)
## ... nonlocal x
## Traceback (most recent call last):
## ...
## SyntaxWarning: name 'x' is assigned to before nonlocal declaration

## >>> def f():
## ... x = 1
## ... nonlocal x
## Traceback (most recent call last):
## ...
## SyntaxWarning: name 'x' is assigned to before nonlocal declaration

From https://bugs.python.org/issue25973
From https://bugs.python.org/issue25973
>>> class A:
... def f(self):
... nonlocal __x
Expand Down