Skip to content

Commit 4de9b67

Browse files
committed
Add test case
1 parent 310730b commit 4de9b67

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test-data/unit/check-inference.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,3 +3874,29 @@ def foo(fdst: SupportsWrite[AnyStr]) -> None: ...
38743874

38753875
x: IO[str]
38763876
foo(x)
3877+
3878+
[case testTypeVarValueConstraintAgainstGenericProtocol2]
3879+
from typing import Generic, Protocol, TypeVar, overload
3880+
3881+
AnyStr = TypeVar("AnyStr", str, bytes)
3882+
T_co = TypeVar("T_co", covariant=True)
3883+
T_contra = TypeVar("T_contra", contravariant=True)
3884+
3885+
class SupportsRead(Generic[T_co]):
3886+
def read(self) -> T_co: ...
3887+
3888+
class SupportsWrite(Protocol[T_contra]):
3889+
def write(self, s: T_contra) -> object: ...
3890+
3891+
def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr]) -> None: ...
3892+
3893+
class WriteToMe(Generic[AnyStr]):
3894+
@overload
3895+
def write(self: WriteToMe[str], s: str) -> int: ...
3896+
@overload
3897+
def write(self: WriteToMe[bytes], s: bytes) -> int: ...
3898+
def write(self, s): ...
3899+
3900+
class WriteToMeOrReadFromMe(WriteToMe[AnyStr], SupportsRead[AnyStr]): ...
3901+
3902+
copyfileobj(WriteToMeOrReadFromMe[bytes](), WriteToMe[bytes]())

0 commit comments

Comments
 (0)