You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
however the else block doesn't narrow the type to non-awaitable. Shouldn't it? Some of the other is... functions in inspect seem to use TypeIs as well.
My understanding is that TypeIs has no defined behaviour for structural types (i.e. Callable), so making this change in typeshed wouldn’t necessarily guarantee you anything. (Though personally I wish the TypeIs spec would formally support Callable, but hey)
I have a similar situation as @Redoubts is the solution as simple as making a pr switching from TypeGuard to TypeIs for inspect.iscoroutinefunction? I'm not too familiar with their differences.
I left a comment on the linked PR, but basically I don't believe there is any way to definitively type a function declared with async def as being different from a synchronous function that returns an Awaitable/CoroutineType/etc.
Perhaps a new type is needed, something like AsyncCallable, which would be what a function is when defined as async def
Activity
srittau commentedon Mar 20, 2026
I assume changing the return type to
TypeIswas deliberately left out of #11823. Maybe @JelleZijlstra can provide some insight?dchevell commentedon Apr 20, 2026
My understanding is that
TypeIshas no defined behaviour for structural types (i.e.Callable), so making this change in typeshed wouldn’t necessarily guarantee you anything. (Though personally I wish theTypeIsspec would formally supportCallable, but hey)Edit: see https://discuss.python.org/t/specs-clarification-typeis-works-with-all-types-structural-or-nominal/95120
JelleZijlstra commentedon Apr 20, 2026
That is false.
InvincibleRMC commentedon Jun 7, 2026
I have a similar situation as @Redoubts is the solution as simple as making a pr switching from
TypeGuardtoTypeIsforinspect.iscoroutinefunction? I'm not too familiar with their differences.linuxdaemon commentedon Oct 31, 2026
I left a comment on the linked PR, but basically I don't believe there is any way to definitively type a function declared with
async defas being different from a synchronous function that returns an Awaitable/CoroutineType/etc.Perhaps a new type is needed, something like
AsyncCallable, which would be what a function is when defined asasync def