[New-bugs-announce] [issue31161] Only check for print and exec parentheses cases for SyntaxError, not subclasses

Martijn Pieters report at bugs.python.org
Wed Aug 9 09:31:18 EDT 2017


New submission from Martijn Pieters:

SyntaxError.__init__() checks for the `print` and `exec` error cases where the user forgot to use parentheses:

>>> exec 1
  File "<stdin>", line 1
    exec 1
         ^
SyntaxError: Missing parentheses in call to 'exec'

>>> print 1
  File "<stdin>", line 1
    print 1
          ^
SyntaxError: Missing parentheses in call to 'print'

However, this check is also applied to *subclasses* of SyntaxError:

>>> if True:
... print "Look ma, no parens!"
  File "<stdin>", line 2
    print "Look ma, no parens!"
        ^
IndentationError: Missing parentheses in call to 'print'

and

>>> compile('if 1:\n    1\n\tprint "Look ma, tabs!"', '', 'single')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 3
    print "Look ma, tabs!"
                         ^
TabError: Missing parentheses in call to 'print'

Perhaps the check needs to be limited to just the exact type.

----------
messages: 300002
nosy: mjpieters
priority: normal
severity: normal
status: open
title: Only check for print and exec parentheses cases for SyntaxError, not subclasses

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31161>
_______________________________________


More information about the New-bugs-announce mailing list