gh-94912: Adjusted check for non-standard coroutine function marker. (#100935)

The initial implementation did not correctly identify explicitly
marked class instances.

Follow up to 532aa4e4e0
This commit is contained in:
Carlton Gibson 2023-01-11 22:17:26 +01:00 committed by GitHub
parent 6e4e14d98f
commit 07a87f74fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -399,8 +399,6 @@ def _has_coroutine_mark(f):
while ismethod(f):
f = f.__func__
f = functools._unwrap_partial(f)
if not (isfunction(f) or _signature_is_functionlike(f)):
return False
return getattr(f, "_is_coroutine_marker", None) is _is_coroutine_marker
def markcoroutinefunction(func):

View File

@ -223,6 +223,10 @@ class TestPredicates(IsTestBase):
self.assertFalse(inspect.iscoroutinefunction(Cl))
# instances with async def __call__ are NOT recognised.
self.assertFalse(inspect.iscoroutinefunction(Cl()))
# unless explicitly marked.
self.assertTrue(inspect.iscoroutinefunction(
inspect.markcoroutinefunction(Cl())
))
class Cl2:
@inspect.markcoroutinefunction
@ -232,6 +236,10 @@ class TestPredicates(IsTestBase):
self.assertFalse(inspect.iscoroutinefunction(Cl2))
# instances with marked __call__ are NOT recognised.
self.assertFalse(inspect.iscoroutinefunction(Cl2()))
# unless explicitly marked.
self.assertTrue(inspect.iscoroutinefunction(
inspect.markcoroutinefunction(Cl2())
))
class Cl3:
@inspect.markcoroutinefunction