This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2017年08月09日 13:31 by mjpieters, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 3082 | merged | mjpieters, 2017年08月13日 15:01 | |
| PR 3083 | merged | mjpieters, 2017年08月13日 15:03 | |
| Messages (11) | |||
|---|---|---|---|
| msg300002 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2017年08月09日 13:31 | |
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.
|
|||
| msg300003 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2017年08月09日 13:36 | |
Credit for uncovering this gem: https://stackoverflow.com/questions/45591883/why-is-an-indentionerror-being-raised-here-rather-than-a-syntaxerror |
|||
| msg300076 - (view) | Author: Steven D'Aprano (steven.daprano) * (Python committer) | Date: 2017年08月10日 12:18 | |
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: - you get an IndentationError (or TabError); - and the error message *also* tells you that print is missing parens. 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. |
|||
| msg300109 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2017年08月10日 15:48 | |
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. |
|||
| msg300158 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年08月11日 09:00 | |
> Perhaps the check needs to be limited to just the exact type. Looks reasonable to me. Do you want to provide a PR Martijn? |
|||
| msg300208 - (view) | Author: Steven D'Aprano (steven.daprano) * (Python committer) | Date: 2017年08月13日 00:21 | |
> > Perhaps the check needs to be limited to just the exact type. > Looks reasonable to me. Do you want to provide a PR Martijn? You realise that is making the current traceback *less* informative instead of more informative? I think that's going backwards -- useful information about the syntax errors are being discarded. "Practicality beats purity" -- the current behaviour is helpful, even if it mixes information about two errors into one traceback. |
|||
| msg300214 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2017年08月13日 08:10 | |
The current traceback is incorrect. It mixes exception type and message from different errors. |
|||
| msg300220 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2017年08月13日 14:52 | |
This does not increase clarity. It creates confusion. There are two distinct syntax errors, and they should be reported separately, just like `print "abc" 42` is two syntax errors; you'll hear about the second one once the first one is fixed. |
|||
| msg300221 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2017年08月13日 14:54 | |
Disregard my last message, I misread Serhiy's sentence (read 'correct' for 'incorrect'). |
|||
| msg300718 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2017年08月22日 20:11 | |
New changeset 680f04a926bce04e4320ba883068c345eba502a6 by Łukasz Langa (Martijn Pieters) in branch '3.6': bpo-31161: only check for parens error for SyntaxError (#3083) https://github.com/python/cpython/commit/680f04a926bce04e4320ba883068c345eba502a6 |
|||
| msg300719 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2017年08月22日 20:16 | |
New changeset 772d809a63f40fd35679da3fb115cdf7fa81bd20 by Łukasz Langa (Martijn Pieters) in branch 'master': bpo-31161: only check for parens error for SyntaxError (#3082) https://github.com/python/cpython/commit/772d809a63f40fd35679da3fb115cdf7fa81bd20 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:49 | admin | set | github: 75344 |
| 2017年08月22日 20:17:57 | lukasz.langa | set | status: open -> closed resolution: fixed stage: needs patch -> resolved |
| 2017年08月22日 20:16:25 | lukasz.langa | set | messages: + msg300719 |
| 2017年08月22日 20:11:11 | lukasz.langa | set | nosy:
+ lukasz.langa messages: + msg300718 |
| 2017年08月13日 15:03:21 | mjpieters | set | pull_requests: + pull_request3125 |
| 2017年08月13日 15:01:30 | mjpieters | set | pull_requests: + pull_request3124 |
| 2017年08月13日 14:54:02 | mjpieters | set | messages: + msg300221 |
| 2017年08月13日 14:52:37 | mjpieters | set | messages: + msg300220 |
| 2017年08月13日 08:10:54 | serhiy.storchaka | set | messages: + msg300214 |
| 2017年08月13日 00:21:13 | steven.daprano | set | messages: + msg300208 |
| 2017年08月11日 09:00:24 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg300158 keywords: + easy (C) stage: needs patch |
| 2017年08月10日 15:48:51 | mjpieters | set | messages: + msg300109 |
| 2017年08月10日 12:18:45 | steven.daprano | set | versions:
+ Python 3.6, Python 3.7 nosy: + steven.daprano messages: + msg300076 components: + Interpreter Core type: behavior |
| 2017年08月09日 13:36:15 | mjpieters | set | messages: + msg300003 |
| 2017年08月09日 13:31:18 | mjpieters | create | |