Skip to content

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

Closed

Description

@lysnikolaou

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

Activity

  1. iritkatriel commented on Nov 7, 2022

    @iritkatriel
    Member

    How do we know which one is wrong?

  2. lysnikolaou commented on Nov 7, 2022

    @lysnikolaou
    MemberAuthor

    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.

  3. iritkatriel commented on Nov 7, 2022

    @iritkatriel
    Member

    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.

  4. lysnikolaou commented on Nov 7, 2022

    @lysnikolaou
    MemberAuthor

    Correct.

  5. added 2 commits that reference this issue on Nov 7, 2022
  6. added a commit that references this issue on Nov 20, 2022
  7. added 2 commits that reference this issue on Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions