Skip to content
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

gh-123440: Improve error message for except as used with not a name #123442

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 28, 2024

The main idea is that this rule is the last in chain. So, any valid cases with NAME expressions are already matched. So, I guess it is safe to use 'except' expression 'as' a=expression later on.

I tried to use a single rule in invalid_except_stmt like:

    | 'except' '*'? expression 'as' a=expression {
        RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
            a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }

but since it is used for both except_block and except_star_block - this produced an incorrect result.

Grammar/python.gram Outdated Show resolved Hide resolved
Copy link
Contributor

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @sobolevn!

@pablogsal
Copy link
Member

Fantastic! Great work and thanks for the comprehensive test cases 🤘

@pablogsal pablogsal merged commit e451a89 into python:main Aug 30, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants