mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-31161: only check for parens error for SyntaxError (#3082)
Subclasses such as IndentError and TabError should not have this message applied.
This commit is contained in:
parent
5df8c589f4
commit
772d809a63
3 changed files with 41 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue