Skip to content

Improve error message for except a as b.c: case #123440

Closed
@sobolevn

Description

@sobolevn

Feature or enhancement

Right now the syntax error is not very clear:
Снимок экрана 2024-08-28 в 21 00 51

I propose to instead use something like:
Снимок экрана 2024-08-28 в 20 59 42

@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 :)

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions