Summary
Consider the following example, where our use of CallableSignature::bind_self to eagerly remove the first parameter leads to a wrong display type of the bound method. The call binding goes through a different code path and leads to the correct result, though:
from __future__ import annotations
from typing import reveal_type, overload
class C[T]:
x: T
@overload
def method(self: C[int]) -> int:
return 0
@overload
def method(self: C[str]) -> str:
return ""
def method(self) -> int | str:
raise NotImplementedError
reveal_type(C[str]().method) # ty: Overload[() -> int, () -> str]
reveal_type(C[str]().method()) # ty: str
https://play.ty.dev/e75a9987-fcee-4bd9-a53f-d7edf9941465
Also related to this, we do not emit an error here. It might be argued that this is fine, though, as long as we're not calling the bound method:
from typing import reveal_type
class C:
def wrong_annotation(self: int) -> int:
return 0
reveal_type(C().wrong_annotation)
https://play.ty.dev/671b14e0-fa24-4ef9-a05d-8e2bfcaffe51
Version
Current main (59c8fda)
Summary
Consider the following example, where our use of
CallableSignature::bind_selfto eagerly remove the first parameter leads to a wrong display type of the bound method. The call binding goes through a different code path and leads to the correct result, though:https://play.ty.dev/e75a9987-fcee-4bd9-a53f-d7edf9941465
Also related to this, we do not emit an error here. It might be argued that this is fine, though, as long as we're not calling the bound method:
https://play.ty.dev/671b14e0-fa24-4ef9-a05d-8e2bfcaffe51
Version
Current
main(59c8fda)