mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
[3.12] gh-120200: Fix inspect.iscoroutinefunction(inspect) is True
corner case (GH-120214) (#120239)
* [3.12] 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
ec7c9d330f
commit
1e7903d549
2 changed files with 4 additions and 3 deletions
|
@ -401,13 +401,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):
|
||||||
"""
|
"""
|
||||||
|
@ -415,7 +415,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):
|
||||||
|
|
|
@ -199,6 +199,7 @@ class TestPredicates(IsTestBase):
|
||||||
inspect.iscoroutinefunction(
|
inspect.iscoroutinefunction(
|
||||||
functools.partial(functools.partial(
|
functools.partial(functools.partial(
|
||||||
gen_coroutine_function_example))))
|
gen_coroutine_function_example))))
|
||||||
|
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