Summary
When evaluating __get__ for during attribute access on an intersection type, ty uses the non-intersected type for the instance parameter.
from typing import Any, Self, overload, reveal_type
class Descriptor:
@overload
def __get__(self, instance: None, owner: type, /) -> Self: ...
@overload
def __get__[T](self, instance: T, owner: type | None = None, /) -> T: ...
def __get__(self, instance: object, owner: type | None = None, /) -> Any: ...
class A:
desc = Descriptor()
class Mixin:
pass
def g(x: A) -> None:
if isinstance(x, Mixin):
reveal_type(x) # Revealed type: `A & Mixin`
reveal_type(x.desc) # Revealed type: `A`
reveal_type(A.desc.__get__(x)) # Revealed type: `A & Mixin`
(Playground)
Possibly related: #1163
Version
0.0.40
Summary
When evaluating
__get__for during attribute access on an intersection type,tyuses the non-intersected type for theinstanceparameter.(Playground)
Possibly related: #1163
Version
0.0.40