Kaydet (Commit) d7604f5d authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) Serhiy Storchaka

bpo-31847: Fix commented out tests in test_syntax. (GH-4084) (#4095)

SyntaxError now is raised instead of SyntaxWarning.
(cherry picked from commit 3b66ebe7)
üst a5f9d24c
...@@ -384,6 +384,15 @@ Misuse of the nonlocal and global statement can lead to a few unique syntax erro ...@@ -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 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):
...@@ -409,24 +418,7 @@ From SF bug #1705365 ...@@ -409,24 +418,7 @@ From SF bug #1705365
... ...
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment