ruff
6c660d8d - [ty] Preserve receiver constraints when binding overloaded methods (#27038)

Commit
28 days ago
[ty] Preserve receiver constraints when binding overloaded methods (#27038) ## Summary Follow-up to [the receiver-constraint review discussion in #24707](https://github.com/astral-sh/ruff/pull/24707#discussion_r3326577303). Prior to this change, we reduced overload receiver matching to a boolean before binding the method. That kept overloads with satisfiable generic receivers, but discarded the constraints needed to specialize the remainder of the signature; structural receivers with contradictory constraints could also remain visible. We now reuse the receiver constraint set produced during binding, existentially prune impossible overloads, and solve exact receiver bounds into the bound signature while retaining one-sided constraints for later callable comparisons. For example: ```py from typing import overload class Box[T]: value: T @overload def method[S](self: "Box[S]", value: S) -> S: ... @overload def method(self, value: bytes) -> bytes: ... def method(self, value: object) -> object: ... reveal_type(Box[str]().method) # Overload[(value: str) -> str, (value: bytes) -> bytes] ``` --------- Co-authored-by: Carl Meyer <carl@astral.sh>
Author
Parents
Loading