@@ -28,7 +28,9 @@ Self = 0
28
28
29
29
T = TypeVar ('T' )
30
30
T_co = TypeVar ('T_co' , covariant = True )
31
+ R_co = TypeVar ('R_co' , covariant = True )
31
32
T_contra = TypeVar ('T_contra' , contravariant = True )
33
+ S_contra = TypeVar ('S_contra' , contravariant = True )
32
34
U = TypeVar ('U' )
33
35
V = TypeVar ('V' )
34
36
S = TypeVar ('S' )
@@ -49,9 +51,9 @@ class Iterator(Iterable[T_co], Protocol):
49
51
@abstractmethod
50
52
def __next__ (self ) -> T_co : pass
51
53
52
- class Generator (Iterator [T ], Generic [T , U , V ]):
54
+ class Generator (Iterator [T_co ], Generic [T_co , S_contra , R_co ]):
53
55
@abstractmethod
54
- def send (self , value : U ) -> T : pass
56
+ def send (self , value : S_contra ) -> T_co : pass
55
57
56
58
@abstractmethod
57
59
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]):
60
62
def close (self ) -> None : pass
61
63
62
64
@abstractmethod
63
- def __iter__ (self ) -> 'Generator[T, U, V ]' : pass
65
+ def __iter__ (self ) -> 'Generator[T_co, S_contra, R_co ]' : pass
64
66
65
- class AsyncGenerator (AsyncIterator [T ], Generic [T , U ]):
67
+ class AsyncGenerator (AsyncIterator [T_co ], Generic [T_co , S_contra ]):
66
68
@abstractmethod
67
- def __anext__ (self ) -> Awaitable [T ]: pass
69
+ def __anext__ (self ) -> Awaitable [T_co ]: pass
68
70
69
71
@abstractmethod
70
- def asend (self , value : U ) -> Awaitable [T ]: pass
72
+ def asend (self , value : S_contra ) -> Awaitable [T_co ]: pass
71
73
72
74
@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
74
76
75
77
@abstractmethod
76
- def aclose (self ) -> Awaitable [T ]: pass
78
+ def aclose (self ) -> Awaitable [T_co ]: pass
77
79
78
80
@abstractmethod
79
- def __aiter__ (self ) -> 'AsyncGenerator[T, U ]' : pass
81
+ def __aiter__ (self ) -> 'AsyncGenerator[T_co, S_contra ]' : pass
80
82
81
- class Awaitable (Protocol [T ]):
83
+ class Awaitable (Protocol [T_co ]):
82
84
@abstractmethod
83
- def __await__ (self ) -> Generator [Any , Any , T ]: pass
85
+ def __await__ (self ) -> Generator [Any , Any , T_co ]: pass
84
86
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
+ ):
86
93
pass
87
94
88
- class Coroutine (Awaitable [V ], Generic [T , U , V ]):
95
+ class Coroutine (Awaitable [R_co ], Generic [T_co , S_contra , R_co ]):
89
96
@abstractmethod
90
- def send (self , value : U ) -> T : pass
97
+ def send (self , value : S_contra ) -> T_co : pass
91
98
92
99
@abstractmethod
93
100
def throw (self , typ : Any , val : Any = None , tb : Any = None ) -> None : pass
94
101
95
102
@abstractmethod
96
103
def close (self ) -> None : pass
97
104
98
- class AsyncIterable (Protocol [T ]):
105
+ class AsyncIterable (Protocol [T_co ]):
99
106
@abstractmethod
100
- def __aiter__ (self ) -> 'AsyncIterator[T ]' : pass
107
+ def __aiter__ (self ) -> 'AsyncIterator[T_co ]' : pass
101
108
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
104
111
@abstractmethod
105
- def __anext__ (self ) -> Awaitable [T ]: pass
112
+ def __anext__ (self ) -> Awaitable [T_co ]: pass
106
113
107
114
class Sequence (Iterable [T_co ], Container [T_co ]):
108
115
@abstractmethod
0 commit comments