Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/graphql/pyutils/is_awaitable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

CO_ITERABLE_COROUTINE = inspect.CO_ITERABLE_COROUTINE

_common_primitives = {int, float, bool, str, list, dict, tuple, type(None)}


def is_awaitable(value: Any) -> TypeGuard[Awaitable]:
"""Return True if object can be passed to an ``await`` expression.

Instead of testing whether the object is an instance of abc.Awaitable, we
check the existence of an `__await__` attribute. This is much faster.
"""
if type(value) in _common_primitives:
return False

return (
# check for coroutine objects
isinstance(value, CoroutineType)
Expand Down
Loading