Make SyntaxError when mixing except/except* point to the offending clause
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
- PR: gh-99215
How do we know which one is wrong?
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.
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.
Correct.