python / python/cpython

`lambda` grammar in the language reference incorrectly allows annotations

Open
#156,675 1 comment 0 reactions 2 assignees View on GitHub

@encukou is already working on this.

Since Aug 30, 2026.

docs topic-parser type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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:

https://github.com/python/cpython/blob/74b944afe32049191674c747e060d8d67a2a1b17/Grammar/python.gram#L922-L924

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.