Skip to content

Descriptor as class attribute is misunderstood #4472

@gvanrossum

Description

@gvanrossum

A descriptor is something with a __get__ method; the return type of __get__ defines the type of the corresponding instance attribute. However the corresponding class attribute ought to be inspectable just as if it was an instance of the descriptor class; right now it is treated as the same type as the instance attribute. Example:

class Descr:
    def __get__(self, *args) -> int: pass
    name: str = 'booh'

class C:
    a = Descr()

reveal_type(C().a)  # int
reveal_type(C.a.name)  # Any # E: "int" has no attribute "name"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions