Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a primitive type check in isawaitable #232

Closed
wants to merge 1 commit into from
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