Skip to content

Commit 950b4fe

Browse files
authored
Add a primitive type check in isawaitable
1 parent 4624444 commit 950b4fe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/graphql/pyutils/is_awaitable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717
CO_ITERABLE_COROUTINE = inspect.CO_ITERABLE_COROUTINE
1818

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

2022
def is_awaitable(value: Any) -> TypeGuard[Awaitable]:
2123
"""Return True if object can be passed to an ``await`` expression.
2224
2325
Instead of testing whether the object is an instance of abc.Awaitable, we
2426
check the existence of an `__await__` attribute. This is much faster.
2527
"""
28+
if type(value) in _common_primitives:
29+
return False
30+
2631
return (
2732
# check for coroutine objects
2833
isinstance(value, CoroutineType)

0 commit comments

Comments
 (0)