@@ -156,6 +156,34 @@ def ckmsg(src, msg):
156156 ckmsg (s , "'continue' not properly in loop" )
157157 ckmsg ("continue\n " , "'continue' not properly in loop" )
158158
159+ def testSyntaxErrorMissingParens (self ):
160+ def ckmsg (src , msg , exception = SyntaxError ):
161+ try :
162+ compile (src , '<fragment>' , 'exec' )
163+ except exception as e :
164+ if e .msg != msg :
165+ self .fail ("expected %s, got %s" % (msg , e .msg ))
166+ else :
167+ self .fail ("failed to get expected SyntaxError" )
168+
169+ s = '''print "old style"'''
170+ ckmsg (s , "Missing parentheses in call to 'print'. "
171+ "Did you mean print(\" old style\" )?" )
172+
173+ s = '''print "old style",'''
174+ ckmsg (s , "Missing parentheses in call to 'print'. "
175+ "Did you mean print(\" old style\" , end=\" \" )?" )
176+
177+ s = '''exec "old style"'''
178+ ckmsg (s , "Missing parentheses in call to 'exec'" )
179+
180+ # should not apply to subclasses, see issue #31161
181+ s = '''if True:\n print "No indent"'''
182+ ckmsg (s , "expected an indented block" , IndentationError )
183+
184+ s = '''if True:\n print()\n \t exec "mixed tabs and spaces"'''
185+ ckmsg (s , "inconsistent use of tabs and spaces in indentation" , TabError )
186+
159187 def testSyntaxErrorOffset (self ):
160188 def check (src , lineno , offset ):
161189 with self .assertRaises (SyntaxError ) as cm :
0 commit comments