mirror of
https://github.com/python/cpython.git
synced 2025-09-29 11:45:57 +00:00
bpo-31847: Fix commented out tests in test_syntax. (GH-4084) (#4095)
SyntaxError now is raised instead of SyntaxWarning.
(cherry picked from commit 3b66ebe772
)
This commit is contained in:
parent
a5f9d24c17
commit
d7604f5d06
1 changed files with 10 additions and 18 deletions
|
@ -384,6 +384,15 @@ Misuse of the nonlocal and global statement can lead to a few unique syntax erro
|
|||
...
|
||||
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):
|
||||
|
@ -409,23 +418,6 @@ From SF bug #1705365
|
|||
...
|
||||
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
|
||||
>>> class A:
|
||||
... def f(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue