@@ -28,10 +28,12 @@ Self = 0
2828
2929T = TypeVar ('T' )
3030T_co = TypeVar ('T_co' , covariant = True )
31+ R_co = TypeVar ('R_co' , covariant = True )
3132T_contra = TypeVar ('T_contra' , contravariant = True )
3233U = TypeVar ('U' )
3334V = TypeVar ('V' )
3435S = TypeVar ('S' )
36+ S_contra = TypeVar ('S_contra' , contravariant = True )
3537
3638# Note: definitions below are different from typeshed, variances are declared
3739# to silence the protocol variance checks. Maybe it is better to use type: ignore?
@@ -49,9 +51,9 @@ class Iterator(Iterable[T_co], Protocol):
4951 @abstractmethod
5052 def __next__ (self ) -> T_co : pass
5153
52- class Generator (Iterator [T ], Generic [T , U , V ]):
54+ class Generator (Iterator [T_co ], Generic [T_co , S_contra , R_co ]):
5355 @abstractmethod
54- def send (self , value : U ) -> T : pass
56+ def send (self , value : S_contra ) -> T_co : pass
5557
5658 @abstractmethod
5759 def throw (self , typ : Any , val : Any = None , tb : Any = None ) -> None : pass
@@ -60,49 +62,54 @@ class Generator(Iterator[T], Generic[T, U, V]):
6062 def close (self ) -> None : pass
6163
6264 @abstractmethod
63- def __iter__ (self ) -> 'Generator[T, U, V ]' : pass
65+ def __iter__ (self ) -> 'Generator[T_co, S_contra, R_co ]' : pass
6466
65- class AsyncGenerator (AsyncIterator [T ], Generic [T , U ]):
67+ class AsyncGenerator (AsyncIterator [T_co ], Generic [T_co , S_contra ]):
6668 @abstractmethod
67- def __anext__ (self ) -> Awaitable [T ]: pass
69+ def __anext__ (self ) -> Awaitable [T_co ]: pass
6870
6971 @abstractmethod
70- def asend (self , value : U ) -> Awaitable [T ]: pass
72+ def asend (self , value : S_contra ) -> Awaitable [T_co ]: pass
7173
7274 @abstractmethod
73- def athrow (self , typ : Any , val : Any = None , tb : Any = None ) -> Awaitable [T ]: pass
75+ def athrow (self , typ : Any , val : Any = None , tb : Any = None ) -> Awaitable [T_co ]: pass
7476
7577 @abstractmethod
76- def aclose (self ) -> Awaitable [T ]: pass
78+ def aclose (self ) -> Awaitable [T_co ]: pass
7779
7880 @abstractmethod
79- def __aiter__ (self ) -> 'AsyncGenerator[T, U ]' : pass
81+ def __aiter__ (self ) -> 'AsyncGenerator[T_co, S_contra ]' : pass
8082
81- class Awaitable (Protocol [T ]):
83+ class Awaitable (Protocol [T_co ]):
8284 @abstractmethod
83- def __await__ (self ) -> Generator [Any , Any , T ]: pass
85+ def __await__ (self ) -> Generator [Any , Any , T_co ]: pass
8486
85- class AwaitableGenerator (Generator [T , U , V ], Awaitable [V ], Generic [T , U , V , S ], metaclass = ABCMeta ):
87+ class AwaitableGenerator (
88+ Awaitable [R_co ],
89+ Generator [T_co , S_contra , R_co ],
90+ Generic [T_co , S_contra , R_co , S ],
91+ metaclass = ABCMeta
92+ ):
8693 pass
8794
88- class Coroutine (Awaitable [V ], Generic [T , U , V ]):
95+ class Coroutine (Awaitable [R_co ], Generic [T_co , S_contra , R_co ]):
8996 @abstractmethod
90- def send (self , value : U ) -> T : pass
97+ def send (self , value : S_contra ) -> T_co : pass
9198
9299 @abstractmethod
93100 def throw (self , typ : Any , val : Any = None , tb : Any = None ) -> None : pass
94101
95102 @abstractmethod
96103 def close (self ) -> None : pass
97104
98- class AsyncIterable (Protocol [T ]):
105+ class AsyncIterable (Protocol [T_co ]):
99106 @abstractmethod
100- def __aiter__ (self ) -> 'AsyncIterator[T ]' : pass
107+ def __aiter__ (self ) -> 'AsyncIterator[T_co ]' : pass
101108
102- class AsyncIterator (AsyncIterable [T ], Protocol ):
103- def __aiter__ (self ) -> 'AsyncIterator[T ]' : return self
109+ class AsyncIterator (AsyncIterable [T_co ], Protocol ):
110+ def __aiter__ (self ) -> 'AsyncIterator[T_co ]' : return self
104111 @abstractmethod
105- def __anext__ (self ) -> Awaitable [T ]: pass
112+ def __anext__ (self ) -> Awaitable [T_co ]: pass
106113
107114class Sequence (Iterable [T_co ], Container [T_co ]):
108115 @abstractmethod
@@ -116,13 +123,13 @@ class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
116123 @overload
117124 def get (self , k : T , default : Union [T_co , V ]) -> Union [T_co , V ]: pass
118125
119- class ContextManager (Generic [T ]):
120- def __enter__ (self ) -> T : pass
126+ class ContextManager (Generic [T_co ]):
127+ def __enter__ (self ) -> T_co : pass
121128 # Use Any because not all the precise types are in the fixtures.
122129 def __exit__ (self , exc_type : Any , exc_value : Any , traceback : Any ) -> Any : pass
123130
124- class AsyncContextManager (Generic [T ]):
125- def __aenter__ (self ) -> Awaitable [T ]: pass
131+ class AsyncContextManager (Generic [T_co ]):
132+ def __aenter__ (self ) -> Awaitable [T_co ]: pass
126133 # Use Any because not all the precise types are in the fixtures.
127134 def __aexit__ (self , exc_type : Any , exc_value : Any , traceback : Any ) -> Awaitable [Any ]: pass
128135
0 commit comments