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
When
__get__and__set__are at different levels in the class hierarchy, they do not seem to be behaving properly. Example:Playground link