-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-40334: Produce better error messages on invalid targets #20106
Conversation
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.
Since the error messages will not change I removed the |
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!
Parser/pegen/pegen.c
Outdated
@@ -2058,7 +2058,7 @@ _PyPegen_make_module(Parser *p, asdl_seq *a) { | |||
// Error reporting helpers | |||
|
|||
expr_ty | |||
_PyPegen_get_invalid_target(expr_ty e) | |||
_PyPegen_get_invalid_target(expr_ty e, int del_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 <[email protected]>
Co-authored-by: Pablo Galindo <[email protected]>
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.
I have updated the PR with the latest changes from #20003 |
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
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
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. |
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. |
I see, didn't notice that. Sorry for distraction.
So, is this error will be kept ( |
I like the |
Same here. |
Parser/pegen.h
Outdated
FOR_TARGETS | ||
} TARGETS_TYPE; | ||
expr_ty _PyPegen_get_invalid_target(expr_ty e, TARGETS_TYPE targets_type); | ||
#define GET_INVALID_TARGET(e) _PyPegen_get_invalid_target(e, STAR_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.
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).
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.
a00b611
to
55b5327
Compare
FYI there is an unrelated CI failure on macOS in test_asyncio. |
Thanks @lysnikolaou for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, @lysnikolaou and @pablogsal, I could not cleanly backport this to |
@lysnikolaou Could you do the manual backport? |
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 <[email protected]> (cherry picked from commit 01ece63)
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 <[email protected]> (cherry picked from commit 01ece63)
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 <[email protected]>
…-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 <[email protected]>
The following error messages get produced:
cannot delete ...
for invaliddel
targetscannot assign to ...
for invalid targets in for and withstatements
Additionally a few
cut
s were added in various places before theinvocation of the
invalid_*
rule, in order to speed thingsup.
https://bugs.python.org/issue40334