Skip to content

Nested class body can read out-of-scope bindings from parent class #782

@samwgoldman

Description

@samwgoldman

Describe the Bug

class A:
    a: int = 0

    class B:
        b = a # should fail, a is not in scope

At runtime this fails with a NameError. We seem to deal with the scope properly from nested def but not from the class body itself.

Sandbox Link

https://pyrefly.org/sandbox/?code=MYGwhgzhAECCBcAoaLpntAlgOwC7QF5oAGRZVUSGAISVXugCNC0g

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    scoping-control-flowissues related to scoping and control flow

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions