Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-40334: Produce better error messages on invalid targets#20106
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
lysnikolaou commented May 15, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up.
Uh oh!
There was an error while loading. Please reload this page.
lysnikolaou commented May 15, 2020
Since the error messages will not change I removed the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gvanrossum left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Parser/pegen/pegen.c Outdated
| expr_ty | ||
| _PyPegen_get_invalid_target(expr_tye) | ||
| _PyPegen_get_invalid_target(expr_tye, intdel_targets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please adopt a naming convention that makes it clear that this is effectively a bool? I was a bit baffled by this for a while. A venerable convention is to use names like is_foo or has_bar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, if is_del is okay, because the questions "What's del, the target, which target?" comes to mind. What do you think?
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Correctly identify invalid targets, when there are multiple context managers in a with statement, avoid SEGFAULT in invalid for targets and improve paremeter naming in _PyPegen_get_invalid_target.
Uh oh!
There was an error while loading. Please reload this page.
pablogsal commented May 17, 2020
I have updated the PR with the latest changes from #20003 |
gvanrossum left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... I poked another hole here. :-(
>>> for i, (f, g()) in 10: pass Assertion failed: (e != NULL && e->kind == Compare_kind), function _PyPegen_get_invalid_for_target, file Parser/pegen/pegen.c, line 2110. Abort trap: 6 gvanrossum commented May 17, 2020
Simpler example that gets the same error: And this too: I recommend extreme caution here. If I can poke holes this quickly, I worry that we may be causing a regression if we rush this in before beta1. We obviously don't have the right testing strategy here. There's nothing that says we have to get this level of detail right in beta1. |
…PyPegen_get_invalid_target
lysnikolaou commented May 17, 2020
I pushed a version that I think is pretty close, but I'm not 100% certain. I agree, that there's no rush to land this and that we should test a bit more. |
isidentical commented Jun 10, 2020
What I meant is that; since this PR already generates 'can't use starred expression here' error messages for some cases, it isn't fully compatible with the old parser.
|
lysnikolaou commented Jun 10, 2020
I think I understand now. Indeed the old parser used to produce Also, I can remember @pablogsal mentioning somewhere that changing just the message is okay in terms of backwards-compatibility. |
isidentical commented Jun 10, 2020
I see, didn't notice that. Sorry for distraction.
So, is this error will be kept ( |
lysnikolaou commented Jun 10, 2020
I like the |
gvanrossum commented Jun 10, 2020
Same here. |
Parser/pegen.h Outdated
| FOR_TARGETS | ||
| } TARGETS_TYPE; | ||
| expr_ty_PyPegen_get_invalid_target(expr_tye, TARGETS_TYPEtargets_type); | ||
| #defineGET_INVALID_TARGET(e) _PyPegen_get_invalid_target(e, STAR_TARGETS) |
pablogsalJun 18, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should surround _PyPegen_get_invalid_target in a CHECK to make sure this does not return NULL (and not crash in that case).
pablogsal left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing it again I have played with it a bit more (before the CHECK commit) and I was not able to break it in any way so I think we can land it now so more people interact with it and it this way we could detect any non-trivial problems if they exist.
lysnikolaou commented Jun 18, 2020
FYI there is an unrelated CI failure on macOS in test_asyncio. |
miss-islington commented Jun 18, 2020
Thanks @lysnikolaou for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
miss-islington commented Jun 18, 2020
Sorry, @lysnikolaou and @pablogsal, I could not cleanly backport this to |
pablogsal commented Jun 18, 2020
@lysnikolaou Could you do the manual backport? |
lysnikolaou commented Jun 18, 2020
Of course, on it. |
…-20106) The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally, a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> (cherry picked from commit 01ece63)
bedevere-bot commented Jun 18, 2020
GH-20973 is a backport of this pull request to the 3.9 branch. |
…-20106) (GH-20973) * bpo-40334: Produce better error messages on invalid targets (GH-20106) The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally, a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> (cherry picked from commit 01ece63)
stestagg commented Jun 20, 2020
FYI, appears to have caused a regression: https://bugs.python.org/issue41060. |
…-20106) The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally, a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
The following error messages get produced:
cannot delete ...for invaliddeltargetscannot assign to ...for invalid targets in for and withstatements
Additionally a few
cuts were added in various places before theinvocation of the
invalid_*rule, in order to speed thingsup.
https://bugs.python.org/issue40334