Right now the syntax error is not very clear:
I propose to instead use something like:
@JelleZijlstra suggested to use similar error messages to := case, where we also only expect a name:
>>> (a.b := 3) File "<unknown>", line 1 (a.b := 3) ^^^ SyntaxError: cannot use assignment expressions with attribute >>> (a[0] := 3) File "<unknown>", line 1 (a[0] := 3) ^^^^ SyntaxError: cannot use assignment expressions with subscript >>> ((a, b) := 3) File "<unknown>", line 1 ((a, b) := 3) ^^^^^^ SyntaxError: cannot use assignment expressions with tuple
I am working on this right now :)
pythongh-123440: Improve error message for `except as` used with not …
In the next PRs I will also address:
>>> import a as x[0] File "<python-input-2>", line 1 import a as x[0] ^ SyntaxError: invalid syntax
>>> match 1: ... case x as y[0]: pass ... File "<python-input-3>", line 2 case x as y[0]: pass ^ SyntaxError: invalid syntax
gh-123440: Improve error message for `except as` used with not a name (…
Activity
pythongh-123440: Improve error message for `except as` used with not …
sobolevn commented on Aug 29, 2024
In the next PRs I will also address:
gh-123440: Improve error message for `except as` used with not a name (…