ruff
b2ea1d37 - [ty] Treat captured bound-method receivers covariantly (#28180)

Commit
74 days ago
[ty] Treat captured bound-method receivers covariantly (#28180) ## Summary Previously, we compared a bound method's captured receiver contravariantly. We now allow the same method bound to a subclass to be a subtype of the method bound to its base class: ```python from ty_extensions import static_assert from ty_extensions._internal import TypeOf, is_subtype_of class Base: def method(self) -> int: ... class Child(Base): ... def check(base: Base, child: Child): # Before: failed assertion. After: passes. static_assert(is_subtype_of(TypeOf[child.method], TypeOf[base.method])) ``` The receiver exposed by `__self__` is an already-captured value, so it is covariant. We also compare the bound signatures, so `Self` in a remaining parameter still follows ordinary callable contravariance. Classmethods follow the same rules.
Author
Parents
Loading