Skip to content

__class__ inside a lambda in class definition is reported as not defined #11511

Description

@adamsol

Describe the bug
The code below is correct in Python (A.f() returns the class), but Pyright reports an error.

As an additional reference, there was a similar issue in Ruff: astral-sh/ruff#20562

Code or Screenshots

class A:
    f = lambda: __class__

"__class__" is not defined (reportUndefinedVariable)

VS Code extension or command-line
VS Code, same in playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions