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

gvanrossum webhook-mailer at python.org
Wed Jan 11 16:17:35 EST 2023


https://github.com/python/cpython/commit/07a87f74faf31cdd755ac7de6d44531139899d1b
commit: 07a87f74faf31cdd755ac7de6d44531139899d1b
branch: main
author: Carlton Gibson <carlton.gibson at noumenal.es>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2023-01-11T13:17:26-08:00
summary:

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 532aa4e4e019812d0388920768ede7c04232ebe1

files:
M Lib/inspect.py
M Lib/test/test_inspect.py

diff --git a/Lib/inspect.py b/Lib/inspect.py
index 3db7745e8a5e..8bb3a375735a 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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):
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index aa757241aca9..92aba519d28a 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -223,6 +223,10 @@ async def __call__(self):
         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 @@ def __call__(self):
         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



More information about the Python-checkins mailing list