@@ -4,7 +4,7 @@ import sys
44import types
55from _typeshed import Self
66from 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
88from types import (
99 AsyncGeneratorType ,
1010 BuiltinFunctionType ,
@@ -25,7 +25,7 @@ from types import (
2525 TracebackType ,
2626 WrapperDescriptorType ,
2727)
28- from typing import Any , ClassVar , NamedTuple , Protocol , TypeVar , Union
28+ from typing import Any , ClassVar , NamedTuple , Protocol , TypeVar , Union , overload
2929from typing_extensions import Literal , ParamSpec , TypeAlias , TypeGuard
3030
3131if sys .version_info >= (3 , 11 ):
@@ -129,6 +129,7 @@ if sys.version_info >= (3, 11):
129129 ]
130130
131131_P = ParamSpec ("_P" )
132+ _T = TypeVar ("_T" )
132133_T_cont = TypeVar ("_T_cont" , contravariant = True )
133134_V_cont = TypeVar ("_V_cont" , contravariant = True )
134135
@@ -176,22 +177,56 @@ def ismethod(object: object) -> TypeGuard[MethodType]: ...
176177def isfunction (object : object ) -> TypeGuard [FunctionType ]: ...
177178
178179if 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 ]]]: ...
181194
182195else :
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 ]]]: ...
185210
186211def isgenerator (object : object ) -> TypeGuard [GeneratorType [Any , Any , Any ]]: ...
187212def iscoroutine (object : object ) -> TypeGuard [CoroutineType [Any , Any , Any ]]: ...
188213def isawaitable (object : object ) -> TypeGuard [Awaitable [Any ]]: ...
189214
190215if 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 ]]]: ...
192222
193223else :
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 ]]]: ...
195230
196231class _SupportsSet (Protocol [_T_cont , _V_cont ]):
197232 def __set__ (self , __instance : _T_cont , __value : _V_cont ) -> None : ...
0 commit comments