bpo-40621: except clauses should use NAME, not target by hauntsaninja · Pull Request #20086 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Grammar/python.gram
25 changes: 25 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,31 @@
...
SyntaxError: no binding for nonlocal '_A__x' found

Tests for try-except clauses:
>>> try:
... ...
... except Exception as a.b:
... pass
Traceback (most recent call last):
...
SyntaxError: invalid syntax

>>> try:
... ...
... except Exception as a[0]:
... pass
Traceback (most recent call last):
...
SyntaxError: invalid syntax

>>> try:
... ...
... except Exception as (a):
... pass
Traceback (most recent call last):
...
SyntaxError: invalid syntax


This tests assignment-context; there was a bug in Python 2.5 where compiling
a complex 'if' (one with 'elif') would fail to notice an invalid suite,
Expand Down
12 changes: 6 additions & 6 deletions Parser/pegen/parse.c