gh-138864: Improve SyntaxError message for case with expression#138865
gh-138864: Improve SyntaxError message for case with expression#138865sobolevn wants to merge 6 commits intopython:mainfrom
SyntaxError message for case with expression#138865Conversation
ilovelinux
left a comment
There was a problem hiding this comment.
I think some people may be using case ...: to write case _:
Do we want to add this suggestion to the error message?
|
Nope, sorry :) |
| | a="case" patterns guard? ':' NEWLINE !INDENT { | ||
| RAISE_INDENTATION_ERROR("expected an indented block after 'case' statement on line %d", a->lineno) } | ||
| invalid_case_pattern: | ||
| | "case" a=expression guard? ':' block { |
There was a problem hiding this comment.
Maybe it would be better to use this variant?
"case" a=expression 'as'? expression? guard? ':' block
For cases like this:
match ...:
case T[1] as E:
print(1)There was a problem hiding this comment.
This will be slower and a bit more unreadable I think and also allows to match "case" a=expression 'as' guard ':' block which makes no sense.
There was a problem hiding this comment.
We can run for ('as' expression)?. But "slower" sounds ugly, maybe such a little change doesn't worth it.
|
Is there anything else that needs to be done? |
|
This PR is stale because it has been open for 30 days with no activity. |
In my opinion this makes already awesome python error messages (thanks, @pablogsal!) even cooler.
Maybe there are some hidden things that I've missed? I would be happy to fix them :)
In case this complicates our parser quite a bit - feel free to close.
case ...:generates unclearSyntaxErrormessage #138864