mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[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:
parent
afef6b5737
commit
6238174e47
2 changed files with 4 additions and 3 deletions
|
@ -403,13 +403,13 @@ def isgeneratorfunction(obj):
|
||||||
return _has_code_flag(obj, CO_GENERATOR)
|
return _has_code_flag(obj, CO_GENERATOR)
|
||||||
|
|
||||||
# A marker for markcoroutinefunction and iscoroutinefunction.
|
# A marker for markcoroutinefunction and iscoroutinefunction.
|
||||||
_is_coroutine_marker = object()
|
_is_coroutine_mark = object()
|
||||||
|
|
||||||
def _has_coroutine_mark(f):
|
def _has_coroutine_mark(f):
|
||||||
while ismethod(f):
|
while ismethod(f):
|
||||||
f = f.__func__
|
f = f.__func__
|
||||||
f = functools._unwrap_partial(f)
|
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):
|
def markcoroutinefunction(func):
|
||||||
"""
|
"""
|
||||||
|
@ -417,7 +417,7 @@ def markcoroutinefunction(func):
|
||||||
"""
|
"""
|
||||||
if hasattr(func, '__func__'):
|
if hasattr(func, '__func__'):
|
||||||
func = func.__func__
|
func = func.__func__
|
||||||
func._is_coroutine_marker = _is_coroutine_marker
|
func._is_coroutine_marker = _is_coroutine_mark
|
||||||
return func
|
return func
|
||||||
|
|
||||||
def iscoroutinefunction(obj):
|
def iscoroutinefunction(obj):
|
||||||
|
|
|
@ -235,6 +235,7 @@ class TestPredicates(IsTestBase):
|
||||||
gen_coroutine_function_example))))
|
gen_coroutine_function_example))))
|
||||||
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmi))
|
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmi))
|
||||||
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmc))
|
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmc))
|
||||||
|
self.assertFalse(inspect.iscoroutinefunction(inspect))
|
||||||
self.assertFalse(inspect.iscoroutine(gen_coro))
|
self.assertFalse(inspect.iscoroutine(gen_coro))
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue