From fdbeb2b4b67e1e44c96127a06cf1bdf878f4f7ca Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 3 Jul 2015 13:11:35 -0400 Subject: 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. --- Doc/library/inspect.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Doc/library/inspect.rst') diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index d21672f75e..66b92384f0 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -310,6 +310,25 @@ attributes: .. versionadded:: 3.5 +.. function:: isawaitable(object) + + Return true if the object can be used in :keyword:`await` expression. + + Can also be used to distinguish generator-based coroutines from regular + generators:: + + def gen(): + yield + @types.coroutine + def gen_coro(): + yield + + assert not isawaitable(gen()) + assert isawaitable(gen_coro()) + + .. versionadded:: 3.5 + + .. function:: istraceback(object) Return true if the object is a traceback. -- cgit v1.2.1