[3.13] gh-120200: Fix inspect.iscoroutinefunction(inspect) is True corner case (GH-120214) (#120237)

gh-120200: Fix `inspect.iscoroutinefunction(inspect) is True` corner case (GH-120214)
(cherry picked from commit 10fb1b8f36)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2024-06-07 18:26:30 +02:00 committed by GitHub
parent afef6b5737
commit 6238174e47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View file

@ -403,13 +403,13 @@ def isgeneratorfunction(obj):
return _has_code_flag(obj, CO_GENERATOR)
# A marker for markcoroutinefunction and iscoroutinefunction.
_is_coroutine_marker = object()
_is_coroutine_mark = object()
def _has_coroutine_mark(f):
while ismethod(f):
f = f.__func__
f = functools._unwrap_partial(f)
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_mark
def markcoroutinefunction(func):
"""
@ -417,7 +417,7 @@ def markcoroutinefunction(func):
"""
if hasattr(func, '__func__'):
func = func.__func__
func._is_coroutine_marker = _is_coroutine_marker
func._is_coroutine_marker = _is_coroutine_mark
return func
def iscoroutinefunction(obj):