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

Make SyntaxError when mixing except/except* point to the offending clause #99211

Open
lysnikolaou opened this issue Nov 7, 2022 · 4 comments

Comments

@lysnikolaou
Copy link
Contributor

lysnikolaou commented Nov 7, 2022

After #99160, the SyntaxError points to the try keyword, but I think it would be relatively easy to make it point to the except or except* (whichever one is responsible for the SyntaxError) by extracting different alternatives. Do you think that pointing to the try is good enough? @iritkatriel @pablogsal

@iritkatriel
Copy link
Member

iritkatriel commented Nov 7, 2022

How do we know which one is wrong?

@lysnikolaou
Copy link
Contributor Author

lysnikolaou commented Nov 7, 2022

I'm not sure whether this would work, but I was thinking that we could do something like this:

invalid_try_stmt:
   ...
   | 'try' ':' block* except_block+ a='except' b='*' expression ['as' NAME] ':' block+ {
        RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot have 'except*' on a 'try' statement with 'except'") }
   | 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' block+ {
        RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have 'except' on a 'try' statement with 'except*'") }

I haven't tested it, but I can spend some time on it later today or early tomorrow to see if it'd work.

@iritkatriel
Copy link
Member

iritkatriel commented Nov 7, 2022

Yes, I guess this might be better than the try. Even if the first clause was the wrong one, this points to where the type flips.

@lysnikolaou
Copy link
Contributor Author

lysnikolaou commented Nov 7, 2022

Correct.

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

No branches or pull requests

2 participants