Skip to content

Commit

Permalink
Add a primitive type check in isawaitable
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 authored Dec 13, 2024
1 parent 4624444 commit 950b4fe
Showing 1 changed file with 5 additions and 0 deletions.
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

0 comments on commit 950b4fe

Please sign in to comment.