]> granicus.if.org Git - python/commitdiff
bpo-31847: Fix commented out tests in test_syntax. (GH-4084) (#4095)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 23 Oct 2017 22:08:03 +0000 (15:08 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 23 Oct 2017 22:08:03 +0000 (01:08 +0300)
SyntaxError now is raised instead of SyntaxWarning.
(cherry picked from commit 3b66ebe7727dba68c2c6ccf0cd85a4c31255b9b4)

Lib/test/test_syntax.py

index 7f7e6dafcf9008708646d3c3b00334ce9e9d862b..b7095a2cdb030b033c5e42dba420a30b5e83a67d 100644 (file)
@@ -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,24 +418,7 @@ 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
+From https://bugs.python.org/issue25973
    >>> class A:
    ...     def f(self):
    ...         nonlocal __x