8000 gh-94912: Added marker for non-standard coroutine function detection by carltongibson · Pull Request #99247 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

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
Renamed to _is_coroutine_marker.
  • Loading branch information
carltongibson committed Dec 13, 2022
commit c073cf79867a702dc4de6a0659dd9d16bfe4b44e
12 changes: 6 additions & 6 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ def isgeneratorfunction(obj):
return _has_code_flag(obj, CO_GENERATOR)

# A marker for markcoroutinefunction and iscoroutinefunction.
_is_coroutine = object()
_is_coroutine_marker = object()

def markcoroutinefunction(func):
"""
Decorator to ensure callable is recognised as a coroutine function.
"""
if hasattr(func, '__func__'):
func = func.__func__
func._is_coroutine = _is_coroutine
func._is_coroutine_marker = _is_coroutine_marker
return func

def iscoroutinefunction(obj):
Expand All @@ -412,10 +412,10 @@ def iscoroutinefunction(obj):
"""
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:
# _is_coroutine_marker.
f = getattr(getattr(obj, "__func__", obj), "_is_coroutine_marker", None)
c = getattr(obj.__call__, "_is_coroutine_marker", None)
if f is _is_coroutine_marker or c is _is_coroutine_marker:
return True

return _has_code_flag(obj, CO_COROUTINE) or (
Expand Down
0