Skip to content

"SyntaxError: cannot have both 'except' and 'except*' on the same 'try'" traceback point to a confusing place #99153

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

Closed
ProgramRipper opened this issue Nov 6, 2022 · 0 comments · Fixed by #99160
Labels
3.11 only security fixes 3.12 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ProgramRipper
Copy link

ProgramRipper commented Nov 6, 2022

Bug report

Given the following codes:

try:
    ...
except* Exception:
    ...
except Exception: # SyntaxError here
    ...

# but traceback point here

Traceback:

  File "main.py", line 8
    # but traceback point here
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

and:

try:
    ...
except* Exception:
    ...
except Exception: # SyntaxError here
    ...

def next_scope(): # but traceback point here
    ...

Traceback:

  File "main.py", line 8
    def next_scope(): # but traceback point here
    ^^^
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

The traceback points to a confusing place (the last line of the file or the beginning of the next structure statement) rather than the location of the syntax error.
The traceback I expect is:

  File "main.py", line 5
    except Exception: # SyntaxError here
    ^^^^^^
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'

Your environment

  • CPython versions tested on: 3.11.0
  • Operating system and architecture: Ubuntu 22.04 x86_64
@ProgramRipper ProgramRipper added the type-bug An unexpected behavior, bug, or error label Nov 6, 2022
@iritkatriel iritkatriel added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.11 only security fixes 3.12 only security fixes labels Nov 6, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 6, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 6, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants