From e2f5c7644077f2445db6a9cc1fe65ff364696dd9 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 24 Oct 2017 00:27:14 +0300 Subject: [PATCH] bpo-31847: Fix commented out tests in test_syntax. (GH-4084) SyntaxError now is raised instead of SyntaxWarning. (cherry picked from commit 3b66ebe7727dba68c2c6ccf0cd85a4c31255b9b4) --- Lib/test/test_syntax.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 7f7e6dafcf9008..b7095a2cdb030b 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -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): @@ -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