Skip to content

addition of error message for invalid statements in pep #92672

Closed
@vainaixr

Description

@vainaixr

current scenario -

let us take PEP-572,

in
https://peps.python.org/pep-0572/#scope-of-the-target
it has some code like this,

[[(j := j) for i in range(5)] for j in range(5)] # INVALID
[i := 0 for i, j in stuff]                       # INVALID
[i+1 for i in (i := stuff)]                      # INVALID

but it does not specify what error will be raised for these.

expected scenario -

the error message is also described in the pep.
so, the above would become,

[[(j := j) for i in range(5)] for j in range(5)] # INVALID

raises,

SyntaxError: assignment expression cannot rebind comprehension iteration variable 'j'
[i := 0 for i, j in stuff]                       # INVALID

raises,

SyntaxError: assignment expression cannot rebind comprehension iteration variable 'i'
[i+1 for i in (i := stuff)]                      # INVALID

raises,

SyntaxError: assignment expression cannot be used in a comprehension iterable expression

in case there are multiple statements which raise the same error message, then could use like,

statement_1 # INVALID
statement_2 # INVALID

both of the above raise,

error_type: error_message

motivation -

it becomes easier to reverse search, like if I get an error, then I could search for it in the pep, and the associated explanation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions