Skip to content

lambda grammar in the language reference incorrectly allows annotations #156675

Description

@StanFromIreland

Bug report

Bug description:

The language reference defines lambda_expr: "lambda" [parameter_list] ":" expression, reusing parameter_list from the function definition. The grammar explicitly avoids this because:

cpython/Grammar/python.gram

Lines 922 to 924 in 74b944a

# lambda_parameters etc. duplicates parameters but without annotations
# or type comments, and if there's no comma after a parameter, we expect
# a colon, not a close parenthesis. (For more, see parameters above.)

So, it uses parameter: identifier [":" expression] which is incorrect since lambda parameters can't be annotated. A separate lambda_parameter_list family of productions is probably needed, although it's not ideal as it would largely be duplicated. @encukou, what do you think?

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Labels

docsDocumentation in the Doc dirtopic-parsertype-bugAn unexpected behavior, bug, or error

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions