Skip to content

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 13, 2025

Снимок экрана 2025-09-13 в 12 53 17

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.

Copy link
Contributor

@ilovelinux ilovelinux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some people may be using case ...: to write case _:

Do we want to add this suggestion to the error message?

@sobolevn
Copy link
Member Author

sobolevn commented Sep 15, 2025

Nope, sorry :)
It is not really 100% expected, people might also mean case Ellipsis: :)

| 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member

@pablogsal pablogsal Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can run for ('as' expression)?. But "slower" sounds ugly, maybe such a little change doesn't worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants