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

gh-94912: Added marker for non-standard coroutine function detection #99247

Merged
merged 16 commits into from
Dec 18, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adjusted implementation.
  • Loading branch information
carltongibson committed Dec 8, 2022
commit 3bc72e2422ba4f44725525c5eb87989c677c6b34
13 changes: 7 additions & 6 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,13 @@ def iscoroutinefunction(obj):
Coroutine functions are normally defined with "async def" syntax, but may
be marked via markcoroutinefunction.
"""
func = getattr(obj, "__func__", obj)
if getattr(func, "_is_coroutine", None) is _is_coroutine:
return True

if not isclass(obj) and callable(obj) and getattr(obj.__call__, "_is_coroutine", None) is _is_coroutine:
return True
if not isclass(obj) and callable(obj):
# Test both the function and the __call__ implementation for the
# _is_coroutine marker.
f = getattr(getattr(obj, "__func__", obj), "_is_coroutine", None)
c = getattr(obj.__call__, "_is_coroutine", None)
if f is _is_coroutine or c is _is_coroutine:
return True

return _has_code_flag(obj, CO_COROUTINE) or (
gvanrossum marked this conversation as resolved.
Show resolved Hide resolved
not isclass(obj) and callable(obj) and _has_code_flag(obj.__call__, CO_COROUTINE)
Expand Down