mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +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
10
Lib/types.py
10
Lib/types.py
|
@ -241,12 +241,12 @@ def coroutine(func):
|
|||
@_functools.wraps(func)
|
||||
def wrapped(*args, **kwargs):
|
||||
coro = func(*args, **kwargs)
|
||||
if coro.__class__ is CoroutineType:
|
||||
# 'coro' is a native coroutine object.
|
||||
if (coro.__class__ is CoroutineType or
|
||||
coro.__class__ is GeneratorType and coro.gi_code.co_flags & 0x100):
|
||||
# 'coro' is a native coroutine object or an iterable coroutine
|
||||
return coro
|
||||
if (coro.__class__ is GeneratorType or
|
||||
(isinstance(coro, _collections_abc.Generator) and
|
||||
not isinstance(coro, _collections_abc.Coroutine))):
|
||||
if (isinstance(coro, _collections_abc.Generator) and
|
||||
not isinstance(coro, _collections_abc.Coroutine)):
|
||||
# 'coro' is either a pure Python generator iterator, or it
|
||||
# implements collections.abc.Generator (and does not implement
|
||||
# collections.abc.Coroutine).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue