-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Only check for print and exec parentheses cases for SyntaxError, not subclasses #75344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
SyntaxError.init() checks for the >>> 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. |
Credit for uncovering this gem: https://stackoverflow.com/questions/45591883/why-is-an-indentionerror-being-raised-here-rather-than-a-syntaxerror |
I'm not sure whether this is a bug or a feature. In the examples you show, we have *both* an IndentationError/TabError and missing parentheses around print. So I'm almost inclined to say that this is right:
Two errors for the price of one! I'm not sure that I would have designed it this way from scratch, but given that it already exists I'm not sure that it should be "fixed". In any case, since the error message itself is not part of the public API, I don't think there's any problem in changing it in a bug-fix release. So *if* we change this, we can change it in 3.6. |
It's confusing; a syntax error reports on the first error found, not two errors at once. The TabError or IndentationError exception detail message itself is lost (it should be "IndentationError: Improper mixture of spaces and tabs." or "TabError: Improper indentation.", respectively). So you end up with an end-user scratching their head, the two parts of the message make no sense together. |
Looks reasonable to me. Do you want to provide a PR Martijn? |
You realise that is making the current traceback *less* informative |
The current traceback is incorrect. It mixes exception type and message from different errors. |
This does not increase clarity. It creates confusion. There are two distinct syntax errors, and they should be reported separately, just like |
Disregard my last message, I misread Serhiy's sentence (read 'correct' for 'incorrect'). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: