mirror of https://github.com/python/cpython.git
bpo-31847: Fix commented out tests in test_syntax. (#4084)
SyntaxError now is raised instead of SyntaxWarning.
This commit is contained in:
parent
828ca59208
commit
3b66ebe772
|
@ -415,6 +415,15 @@
|
||||||
...
|
...
|
||||||
SyntaxError: name 'x' is used prior to nonlocal declaration
|
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):
|
>>> def f(x):
|
||||||
... nonlocal x
|
... nonlocal x
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
|
@ -440,24 +449,7 @@
|
||||||
...
|
...
|
||||||
SyntaxError: nonlocal declaration not allowed at module level
|
SyntaxError: nonlocal declaration not allowed at module level
|
||||||
|
|
||||||
TODO(jhylton): Figure out how to test SyntaxWarning with doctest.
|
From https://bugs.python.org/issue25973
|
||||||
|
|
||||||
## >>> 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
|
|
||||||
>>> class A:
|
>>> class A:
|
||||||
... def f(self):
|
... def f(self):
|
||||||
... nonlocal __x
|
... nonlocal __x
|
||||||
|
|
Loading…
Reference in New Issue