@@ -44,7 +44,8 @@ Literal: _SpecialForm
4444
4545T = TypeVar ('T' )
4646T_co = TypeVar ('T_co' , covariant = True )
47- T_contra = TypeVar ('T_contra' , contravariant = True )
47+ R_co = TypeVar ('R_co' , covariant = True )
48+ S_contra = TypeVar ('S_contra' , contravariant = True )
4849U = TypeVar ('U' )
4950V = TypeVar ('V' )
5051S = TypeVar ('S' )
@@ -82,9 +83,9 @@ class Iterator(Iterable[T_co], Protocol):
8283 @abstractmethod
8384 def __next__ (self ) -> T_co : pass
8485
85- class Generator (Iterator [T ], Generic [T , U , V ]):
86+ class Generator (Iterator [T_co ], Generic [T_co , S_contra , R_co ]):
8687 @abstractmethod
87- def send (self , value : U ) -> T : pass
88+ def send (self , value : S_contra ) -> T_co : pass
8889
8990 @abstractmethod
9091 def throw (self , typ : Any , val : Any = None , tb : Any = None ) -> None : pass
@@ -93,35 +94,40 @@ class Generator(Iterator[T], Generic[T, U, V]):
9394 def close (self ) -> None : pass
9495
9596 @abstractmethod
96- def __iter__ (self ) -> 'Generator[T, U, V ]' : pass
97+ def __iter__ (self ) -> 'Generator[T_co, S_contra, R_co ]' : pass
9798
98- class AsyncGenerator (AsyncIterator [T ], Generic [T , U ]):
99+ class AsyncGenerator (AsyncIterator [T_co ], Generic [T_co , S_contra ]):
99100 @abstractmethod
100- def __anext__ (self ) -> Awaitable [T ]: pass
101+ def __anext__ (self ) -> Awaitable [T_co ]: pass
101102
102103 @abstractmethod
103- def asend (self , value : U ) -> Awaitable [T ]: pass
104+ def asend (self , value : S_contra ) -> Awaitable [T_co ]: pass
104105
105106 @abstractmethod
106- def athrow (self , typ : Any , val : Any = None , tb : Any = None ) -> Awaitable [T ]: pass
107+ def athrow (self , typ : Any , val : Any = None , tb : Any = None ) -> Awaitable [T_co ]: pass
107108
108109 @abstractmethod
109- def aclose (self ) -> Awaitable [T ]: pass
110+ def aclose (self ) -> Awaitable [T_co ]: pass
110111
111112 @abstractmethod
112- def __aiter__ (self ) -> 'AsyncGenerator[T, U ]' : pass
113+ def __aiter__ (self ) -> 'AsyncGenerator[T_co, S_contra ]' : pass
113114
114115@runtime_checkable
115- class Awaitable (Protocol [T ]):
116+ class Awaitable (Protocol [T_co ]):
116117 @abstractmethod
117- def __await__ (self ) -> Generator [Any , Any , T ]: pass
118+ def __await__ (self ) -> Generator [Any , Any , T_co ]: pass
118119
119- class AwaitableGenerator (Generator [T , U , V ], Awaitable [V ], Generic [T , U , V , S ], metaclass = ABCMeta ):
120+ class AwaitableGenerator (
121+ Awaitable [R_co ],
122+ Generator [T_co , S_contra , R_co ],
123+ Generic [T_co , S_contra , R_co , S ],
124+ metaclass = ABCMeta
125+ ):
120126 pass
121127
122- class Coroutine (Awaitable [V ], Generic [T , U , V ]):
128+ class Coroutine (Awaitable [R_co ], Generic [T_co , S_contra , R_co ]):
123129 @abstractmethod
124- def send (self , value : U ) -> T : pass
130+ def send (self , value : S_contra ) -> T_co : pass
125131
126132 @abstractmethod
127133 def throw (self , typ : Any , val : Any = None , tb : Any = None ) -> None : pass
@@ -130,15 +136,15 @@ class Coroutine(Awaitable[V], Generic[T, U, V]):
130136 def close (self ) -> None : pass
131137
132138@runtime_checkable
133- class AsyncIterable (Protocol [T ]):
139+ class AsyncIterable (Protocol [T_co ]):
134140 @abstractmethod
135- def __aiter__ (self ) -> 'AsyncIterator[T ]' : pass
141+ def __aiter__ (self ) -> 'AsyncIterator[T_co ]' : pass
136142
137143@runtime_checkable
138- class AsyncIterator (AsyncIterable [T ], Protocol ):
139- def __aiter__ (self ) -> 'AsyncIterator[T ]' : return self
144+ class AsyncIterator (AsyncIterable [T_co ], Protocol ):
145+ def __aiter__ (self ) -> 'AsyncIterator[T_co ]' : return self
140146 @abstractmethod
141- def __anext__ (self ) -> Awaitable [T ]: pass
147+ def __anext__ (self ) -> Awaitable [T_co ]: pass
142148
143149class Sequence (Iterable [T_co ], Container [T_co ]):
144150 @abstractmethod
0 commit comments