Skip to content

Class method can't get class fields #647

Open
@ndmitchell

Description

@ndmitchell

Describe the Bug

from typing import reveal_type

class Foo:
    x: str

    @classmethod
    def f(cls) -> None:
        reveal_type(cls.x) # E: Instance-only attribute `x` of class `Foo` is not visible on the class

Both Mypy and Pyright think this should be a str, not an error.

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMogCmAboQIYA2A+vAoQFD0DGFZAzm1AGJhgBc9KEKgAPPlDYwQjYVAACLdmwiEYACzAATQcM2FgUYAAoWbAJRQAtAD4oAOTApCA2bKKlKNRIRMU2AOhEzHVcoIA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    UserBugs reported by external users that should be prioritisedpytorch

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions