summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2024-06-07 15:48:31 (GMT)
committerGitHub <noreply@github.com>2024-06-07 15:48:31 (GMT)
commit10fb1b8f36ab2fc3d2fe7392d5735dd19c5e2365 (patch)
tree358b11eaf02e8a460ebf95be0bbeb674da01bc04
parent9d6604222e9ef4e136ee9ccfa2d4d5ff9feee976 (diff)
downloadcpython-10fb1b8f36ab2fc3d2fe7392d5735dd19c5e2365.zip
cpython-10fb1b8f36ab2fc3d2fe7392d5735dd19c5e2365.tar.gz
cpython-10fb1b8f36ab2fc3d2fe7392d5735dd19c5e2365.tar.bz2
gh-120200: Fix `inspect.iscoroutinefunction(inspect) is True` corner case (#120214)
-rw-r--r--Lib/inspect.py6
-rw-r--r--Lib/test/test_inspect/test_inspect.py1
2 files changed, 4 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index e6e49a4..2b7f8be 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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):
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py
index 65007c1..0a4fa93 100644
--- a/Lib/test/test_inspect/test_inspect.py
+++ b/Lib/test/test_inspect/test_inspect.py
@@ -235,6 +235,7 @@ class TestPredicates(IsTestBase):
gen_coroutine_function_example))))
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmi))
self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmc))
+ self.assertFalse(inspect.iscoroutinefunction(inspect))
self.assertFalse(inspect.iscoroutine(gen_coro))
self.assertTrue(