@@ -4,7 +4,7 @@ import sys
4
4
import types
5
5
from _typeshed import Self
6
6
from collections import OrderedDict
7
- from collections .abc import Awaitable , Callable , Coroutine , Generator , Mapping , Sequence , Set as AbstractSet
7
+ from collections .abc import AsyncGenerator , Awaitable , Callable , Coroutine , Generator , Mapping , Sequence , Set as AbstractSet
8
8
from types import (
9
9
AsyncGeneratorType ,
10
10
BuiltinFunctionType ,
@@ -25,7 +25,7 @@ from types import (
25
25
TracebackType ,
26
26
WrapperDescriptorType ,
27
27
)
28
- from typing import Any , ClassVar , NamedTuple , Protocol , TypeVar , Union
28
+ from typing import Any , ClassVar , NamedTuple , Protocol , TypeVar , Union , overload
29
29
from typing_extensions import Literal , ParamSpec , TypeAlias , TypeGuard
30
30
31
31
if sys .version_info >= (3 , 11 ):
@@ -129,6 +129,7 @@ if sys.version_info >= (3, 11):
129
129
]
130
130
131
131
_P = ParamSpec ("_P" )
132
+ _T = TypeVar ("_T" )
132
133
_T_cont = TypeVar ("_T_cont" , contravariant = True )
133
134
_V_cont = TypeVar ("_V_cont" , contravariant = True )
134
135
@@ -176,22 +177,56 @@ def ismethod(object: object) -> TypeGuard[MethodType]: ...
176
177
def isfunction (object : object ) -> TypeGuard [FunctionType ]: ...
177
178
178
179
if sys .version_info >= (3 , 8 ):
179
- def isgeneratorfunction (obj : object ) -> bool : ...
180
- def iscoroutinefunction (obj : object ) -> bool : ...
180
+ @overload
181
+ def isgeneratorfunction (obj : Callable [..., Generator [Any , Any , Any ]]) -> bool : ...
182
+ @overload
183
+ def isgeneratorfunction (obj : Callable [_P , Any ]) -> TypeGuard [Callable [_P , GeneratorType [Any , Any , Any ]]]: ...
184
+ @overload
185
+ def isgeneratorfunction (obj : object ) -> TypeGuard [Callable [..., GeneratorType [Any , Any , Any ]]]: ...
186
+ @overload
187
+ def iscoroutinefunction (obj : Callable [..., Coroutine [Any , Any , Any ]]) -> bool : ...
188
+ @overload
189
+ def iscoroutinefunction (obj : Callable [_P , Awaitable [_T ]]) -> TypeGuard [Callable [_P , CoroutineType [Any , Any , _T ]]]: ...
190
+ @overload
191
+ def iscoroutinefunction (obj : Callable [_P , object ]) -> TypeGuard [Callable [_P , CoroutineType [Any , Any , Any ]]]: ...
192
+ @overload
193
+ def iscoroutinefunction (obj : object ) -> TypeGuard [Callable [..., CoroutineType [Any , Any , Any ]]]: ...
181
194
182
195
else :
183
- def isgeneratorfunction (object : object ) -> bool : ...
184
- def iscoroutinefunction (object : object ) -> bool : ...
196
+ @overload
197
+ def isgeneratorfunction (object : Callable [..., Generator [Any , Any , Any ]]) -> bool : ...
198
+ @overload
199
+ def isgeneratorfunction (object : Callable [_P , Any ]) -> TypeGuard [Callable [_P , GeneratorType [Any , Any , Any ]]]: ...
200
+ @overload
201
+ def isgeneratorfunction (object : object ) -> TypeGuard [Callable [..., GeneratorType [Any , Any , Any ]]]: ...
202
+ @overload
203
+ def iscoroutinefunction (object : Callable [..., Coroutine [Any , Any , Any ]]) -> bool : ...
204
+ @overload
205
+ def iscoroutinefunction (object : Callable [_P , Awaitable [_T ]]) -> TypeGuard [Callable [_P , CoroutineType [Any , Any , _T ]]]: ...
206
+ @overload
207
+ def iscoroutinefunction (object : Callable [_P , Any ]) -> TypeGuard [Callable [_P , CoroutineType [Any , Any , Any ]]]: ...
208
+ @overload
209
+ def iscoroutinefunction (object : object ) -> TypeGuard [Callable [..., CoroutineType [Any , Any , Any ]]]: ...
185
210
186
211
def isgenerator (object : object ) -> TypeGuard [GeneratorType [Any , Any , Any ]]: ...
187
212
def iscoroutine (object : object ) -> TypeGuard [CoroutineType [Any , Any , Any ]]: ...
188
213
def isawaitable (object : object ) -> TypeGuard [Awaitable [Any ]]: ...
189
214
190
215
if sys .version_info >= (3 , 8 ):
191
- def isasyncgenfunction (obj : object ) -> bool : ...
216
+ @overload
217
+ def isasyncgenfunction (obj : Callable [..., AsyncGenerator [Any , Any ]]) -> bool : ...
218
+ @overload
219
+ def isasyncgenfunction (obj : Callable [_P , Any ]) -> TypeGuard [Callable [_P , AsyncGeneratorType [Any , Any ]]]: ...
220
+ @overload
221
+ def isasyncgenfunction (obj : object ) -> TypeGuard [Callable [..., AsyncGeneratorType [Any , Any ]]]: ...
192
222
193
223
else :
194
- def isasyncgenfunction (object : object ) -> bool : ...
224
+ @overload
225
+ def isasyncgenfunction (object : Callable [..., AsyncGenerator [Any , Any ]]) -> bool : ...
226
+ @overload
227
+ def isasyncgenfunction (object : Callable [_P , Any ]) -> TypeGuard [Callable [_P , AsyncGeneratorType [Any , Any ]]]: ...
228
+ @overload
229
+ def isasyncgenfunction (object : object ) -> TypeGuard [Callable [..., AsyncGeneratorType [Any , Any ]]]: ...
195
230
196
231
class _SupportsSet (Protocol [_T_cont , _V_cont ]):
197
232
def __set__ (self , __instance : _T_cont , __value : _V_cont ) -> None : ...
0 commit comments