mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #24400: Resurrect inspect.isawaitable()
collections.abc.Awaitable and collections.abc.Coroutine no longer use __instancecheck__ hook to detect generator-based coroutines. inspect.isawaitable() can be used to detect generator-based coroutines and to distinguish them from regular generator objects.
This commit is contained in:
parent
2ab5b092e5
commit
fdbeb2b4b6
10 changed files with 92 additions and 39 deletions
|
@ -207,6 +207,13 @@ def iscoroutine(object):
|
|||
"""Return true if the object is a coroutine."""
|
||||
return isinstance(object, types.CoroutineType)
|
||||
|
||||
def isawaitable(object):
|
||||
"""Return true is object can be passed to an ``await`` expression."""
|
||||
return (isinstance(object, types.CoroutineType) or
|
||||
isinstance(object, types.GeneratorType) and
|
||||
object.gi_code.co_flags & CO_ITERABLE_COROUTINE or
|
||||
isinstance(object, collections.abc.Awaitable))
|
||||
|
||||
def istraceback(object):
|
||||
"""Return true if the object is a traceback.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue