ruff
e087358a - [ty] Preserve constraints from bound receivers (#26776)

Commit
28 days ago
[ty] Preserve constraints from bound receivers (#26776) ## Summary Binding a method currently removes its receiver parameter and loses any relationship between the concrete receiver and an explicit receiver annotation. For a method like `[T](self: T, value: T) -> T`, that lets later callable comparisons choose `T = int` even when the method is bound to an unrelated class. This PR retains that receiver relation on the bound signature while the signature is freshened, specialized, and compared. The relation participates in existential callable-local inference, and the runtime receiver remains distinct from the type used to replace `typing.Self`, which is necessary for class methods and constructors. For example, we previously accepted this assignment: ```python from typing import Callable class C: def method[T](self: T, value: T) -> T: return self method: Callable[[int], int] = C().method ``` Binding `C().method` requires `C` to be assignable to `T`. We can therefore no longer choose `T = int` merely to satisfy the target callable, and now report this as an invalid assignment (This pass supports unbounded receiver TypeVars, but declared bounds and constraints are deferred for now... Tacking those on led to ecosystem failures around recursive protocols.)
Author
Parents
Loading