Skip to content

Commit 9961179

Browse files
authored
gh-142418: Simplify _has_coroutine_mark by removing unnecessary cycle-detection logic
1 parent dba7cb9 commit 9961179

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

Lib/inspect.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,23 +307,17 @@ def isgeneratorfunction(obj):
307307

308308
def _has_coroutine_mark(f):
309309
while True:
310+
# Direct marker check
310311
if getattr(f, "_is_coroutine_marker", None) is _is_coroutine_mark:
311312
return True
312313

313-
pm = getattr(f, "__partialmethod__", None)
314-
if isinstance(pm, functools.partialmethod):
315-
f = pm
316-
continue
317-
318-
if isinstance(f, functools.partialmethod):
319-
f = getattr(f, 'func')
320-
continue
321-
314+
# Methods: unwrap first (methods cannot be coroutine-marked)
322315
if ismethod(f):
323316
f = f.__func__
324317
continue
325318

326-
if isinstance(f, functools.partial):
319+
# partial and partialmethod share .func
320+
if isinstance(f, (functools.partial, functools.partialmethod)):
327321
f = f.func
328322
continue
329323

0 commit comments

Comments
 (0)