Skip to content

Commit 1e7903d

Browse files
authored
[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 10fb1b8) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent ec7c9d3 commit 1e7903d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Lib/inspect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,21 @@ def isgeneratorfunction(obj):
401401
return _has_code_flag(obj, CO_GENERATOR)
402402

403403
# A marker for markcoroutinefunction and iscoroutinefunction.
404-
_is_coroutine_marker = object()
404+
_is_coroutine_mark = object()
405405

406406
def _has_coroutine_mark(f):
407407
while ismethod(f):
408408
f = f.__func__
409409
f = functools._unwrap_partial(f)
410-
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker
410+
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_mark
411411

412412
def markcoroutinefunction(func):
413413
"""
414414
Decorator to ensure callable is recognised as a coroutine function.
415415
"""
416416
if hasattr(func, '__func__'):
417417
func = func.__func__
418-
func._is_coroutine_marker = _is_coroutine_marker
418+
func._is_coroutine_marker = _is_coroutine_mark
419419
return func
420420

421421
def iscoroutinefunction(obj):

Lib/test/test_inspect/test_inspect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def test_iscoroutine(self):
199199
inspect.iscoroutinefunction(
200200
functools.partial(functools.partial(
201201
gen_coroutine_function_example))))
202+
self.assertFalse(inspect.iscoroutinefunction(inspect))
202203
self.assertFalse(inspect.iscoroutine(gen_coro))
203204

204205
self.assertTrue(

0 commit comments

Comments
 (0)