Skip to content

Commit 7b6889a

Browse files
committed
pythongh-94912: Adjusted check for non-standard coroutine function marker.
The initial implementation did not correctly identify explicitly marked class instances. Follow up to 532aa4e
1 parent 8795ad1 commit 7b6889a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Lib/inspect.py

-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ def _has_coroutine_mark(f):
399399
while ismethod(f):
400400
f = f.__func__
401401
f = functools._unwrap_partial(f)
402-
if not (isfunction(f) or _signature_is_functionlike(f)):
403-
return False
404402
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker
405403

406404
def markcoroutinefunction(func):

Lib/test/test_inspect.py

+8
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ async def __call__(self):
223223
self.assertFalse(inspect.iscoroutinefunction(Cl))
224224
# instances with async def __call__ are NOT recognised.
225225
self.assertFalse(inspect.iscoroutinefunction(Cl()))
226+
# unless explicitly marked.
227+
self.assertTrue(inspect.iscoroutinefunction(
228+
inspect.markcoroutinefunction(Cl())
229+
))
226230

227231
class Cl2:
228232
@inspect.markcoroutinefunction
@@ -232,6 +236,10 @@ def __call__(self):
232236
self.assertFalse(inspect.iscoroutinefunction(Cl2))
233237
# instances with marked __call__ are NOT recognised.
234238
self.assertFalse(inspect.iscoroutinefunction(Cl2()))
239+
# unless explicitly marked.
240+
self.assertTrue(inspect.iscoroutinefunction(
241+
inspect.markcoroutinefunction(Cl2())
242+
))
235243

236244
class Cl3:
237245
@inspect.markcoroutinefunction

0 commit comments

Comments
 (0)