Skip to content

Commit 3bc72e2

Browse files
committed
Adjusted implementation.
1 parent b7249a8 commit 3bc72e2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/inspect.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,13 @@ def iscoroutinefunction(obj):
410410
Coroutine functions are normally defined with "async def" syntax, but may
411411
be marked via markcoroutinefunction.
412412
"""
413-
func = getattr(obj, "__func__", obj)
414-
if getattr(func, "_is_coroutine", None) is _is_coroutine:
415-
return True
416-
417-
if not isclass(obj) and callable(obj) and getattr(obj.__call__, "_is_coroutine", None) is _is_coroutine:
418-
return True
413+
if not isclass(obj) and callable(obj):
414+
# Test both the function and the __call__ implementation for the
415+
# _is_coroutine marker.
416+
f = getattr(getattr(obj, "__func__", obj), "_is_coroutine", None)
417+
c = getattr(obj.__call__, "_is_coroutine", None)
418+
if f is _is_coroutine or c is _is_coroutine:
419+
return True
419420

420421
return _has_code_flag(obj, CO_COROUTINE) or (
421422
not isclass(obj) and callable(obj) and _has_code_flag(obj.__call__, CO_COROUTINE)

0 commit comments

Comments
 (0)