ruff
a5cc4e79 - [ty] Narrow bound method overloads by receiver (#24707)

Commit
5 hours ago
[ty] Narrow bound method overloads by receiver (#24707) ## Summary Given: ```python from typing import overload class Base: @overload def convert(self: "Base", x: int) -> int: ... @overload def convert(self: "Child", x: str) -> str: ... def convert(self, x: int | str) -> int | str: return x class Child(Base): ... ``` On main, we treat `Base().convert` as if both overloads are still possible, including the overload that requires `self: "Child"`. After this PR: ```python reveal_type(Base().convert) # bound method Base.convert(x: int) -> int reveal_type(Child().convert) # Overload[(x: int) -> int, (x: str) -> str] ``` So `Base().convert("x")` is no longer considered valid via narrowing on the actual receiver type. Closes https://github.com/astral-sh/ty/issues/2693. Closes https://github.com/astral-sh/ty/issues/2612. Closes https://github.com/astral-sh/ty/issues/3380. Closes https://github.com/astral-sh/ty/issues/1169.
Author
Parents
Loading