summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartijn Pieters <github.com@zopatista.com>2017-08-22 20:16:23 (GMT)
committerƁukasz Langa <lukasz@langa.pl>2017-08-22 20:16:23 (GMT)
commit772d809a63f40fd35679da3fb115cdf7fa81bd20 (patch)
tree265d99b3470b6413666c5f2ce0e73dd564fb052e /Lib
parent5df8c589f4ec3d8c1ccd115dc030fa7596c1c75d (diff)
downloadcpython-772d809a63f40fd35679da3fb115cdf7fa81bd20.zip
cpython-772d809a63f40fd35679da3fb115cdf7fa81bd20.tar.gz
cpython-772d809a63f40fd35679da3fb115cdf7fa81bd20.tar.bz2
bpo-31161: only check for parens error for SyntaxError (#3082)
Subclasses such as IndentError and TabError should not have this message applied.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 3378ceb..a25f3bf 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -156,6 +156,34 @@ class ExceptionTests(unittest.TestCase):
ckmsg(s, "'continue' not properly in loop")
ckmsg("continue\n", "'continue' not properly in loop")
+ def testSyntaxErrorMissingParens(self):
+ def ckmsg(src, msg, exception=SyntaxError):
+ try:
+ compile(src, '<fragment>', 'exec')
+ except exception as e:
+ if e.msg != msg:
+ self.fail("expected %s, got %s" % (msg, e.msg))
+ else:
+ self.fail("failed to get expected SyntaxError")
+
+ s = '''print "old style"'''
+ ckmsg(s, "Missing parentheses in call to 'print'. "
+ "Did you mean print(\"old style\")?")
+
+ s = '''print "old style",'''
+ ckmsg(s, "Missing parentheses in call to 'print'. "
+ "Did you mean print(\"old style\", end=\" \")?")
+
+ s = '''exec "old style"'''
+ ckmsg(s, "Missing parentheses in call to 'exec'")
+
+ # should not apply to subclasses, see issue #31161
+ s = '''if True:\nprint "No indent"'''
+ ckmsg(s, "expected an indented block", IndentationError)
+
+ s = '''if True:\n print()\n\texec "mixed tabs and spaces"'''
+ ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError)
+
def testSyntaxErrorOffset(self):
def check(src, lineno, offset):
with self.assertRaises(SyntaxError) as cm: