@@ -3900,3 +3900,42 @@ class WriteToMe(Generic[AnyStr]):
39003900class WriteToMeOrReadFromMe(WriteToMe[AnyStr], SupportsRead[AnyStr]): ...
39013901
39023902copyfileobj(WriteToMeOrReadFromMe[bytes](), WriteToMe[bytes]())
3903+
3904+ [case testOverloadedMethodWithExplictSelfTypes]
3905+ from typing import Generic, overload, Protocol, TypeVar, Union
3906+
3907+ AnyStr = TypeVar("AnyStr", str, bytes)
3908+ T_co = TypeVar("T_co", covariant=True)
3909+ T_contra = TypeVar("T_contra", contravariant=True)
3910+
3911+ class SupportsRead(Protocol[T_co]):
3912+ def read(self) -> T_co: ...
3913+
3914+ class SupportsWrite(Protocol[T_contra]):
3915+ def write(self, s: T_contra) -> int: ...
3916+
3917+ class Input(Generic[AnyStr]):
3918+ def read(self) -> AnyStr: ...
3919+
3920+ class Output(Generic[AnyStr]):
3921+ @overload
3922+ def write(self: Output[str], s: str) -> int: ...
3923+ @overload
3924+ def write(self: Output[bytes], s: bytes) -> int: ...
3925+ def write(self, s: Union[str, bytes]) -> int: ...
3926+
3927+ def f(src: SupportsRead[AnyStr], dst: SupportsWrite[AnyStr]) -> None: ...
3928+
3929+ def g1(a: Input[bytes], b: Output[bytes]) -> None:
3930+ f(a, b)
3931+
3932+ def g2(a: Input[bytes], b: Output[bytes]) -> None:
3933+ f(a, b)
3934+
3935+ def g3(a: Input[str], b: Output[bytes]) -> None:
3936+ f(a, b) # E: Cannot infer type argument 1 of "f"
3937+
3938+ def g4(a: Input[bytes], b: Output[str]) -> None:
3939+ f(a, b) # E: Cannot infer type argument 1 of "f"
3940+
3941+ [builtins fixtures/tuple.pyi]
0 commit comments