Skip to content

Fails to parse lambda in PEP 695 TypeVar bound #4599

@15r10nk

Description

@15r10nk

Describe the bug

The following code can not be parsed/formatted by black:

class name_5[name_4: lambda: something]:
     pass
❯ black -t py312 bug.py
error: cannot format bug.py: Cannot parse for target version Python 3.12: 1:21: class name_5[name_4: lambda: something]:

Oh no! 💥 💔 💥
1 file failed to reformat.

but it can be parsed by cpython.

python3.12 scripts/min_code.py

Environment

  • Black's version: current main (00c0d6d)
  • OS and Python version: Linux/Python 3.12

Additional context

The bug was found by pysource-codegen (see #3908)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: parserHow we parse code. Or fail to parse it.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions