Skip to content

Incorrect type when descriptors are at different levels in the class hierarchy #11401

@mfish33

Description

@mfish33

When __get__ and __set__ are at different levels in the class hierarchy, they do not seem to be behaving properly. Example:

from typing import assert_type, cast, Any

class AttributeGet[ T ]:
   def __get__( self, instance: Any, owner: Any = None ) -> T:
      return cast( Any, None )

class Attribute[ T, U ]( AttributeGet[ T ] ):
   def __set__( self, instance: Any, object: T | U ) -> None:
      pass

class StrInt( Attribute[ int, str] ):
    pass

class MyContainer:
   si: StrInt

c = MyContainer()
c.si = "2"
assert_type( c.si, int ) # ERROR HERE

Playground link

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions