]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-102748: remove legacy support for generator based coroutines from `asyncio.iscorou...
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Thu, 16 Mar 2023 14:58:10 +0000 (20:28 +0530)
committerGitHub <noreply@github.com>
Thu, 16 Mar 2023 14:58:10 +0000 (20:28 +0530)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Doc/whatsnew/3.12.rst
Lib/asyncio/coroutines.py
Lib/test/test_asyncio/test_pep492.py
Misc/NEWS.d/next/Library/2023-03-16-08-17-29.gh-issue-102748.WNACpI.rst [new file with mode: 0644]

index 217ffec1ee100747c4ff2c573d862337cd276cf0..b9c668543e1b73052392b7fd1cc11dde745a94e3 100644 (file)
@@ -237,6 +237,10 @@ asyncio
 * Add C implementation of :func:`asyncio.current_task` for 4x-6x speedup.
   (Contributed by Itamar Ostricher and Pranav Thulasiram Bhat in :gh:`100344`.)
 
+* :func:`asyncio.iscoroutine` now returns ``False`` for generators as
+  :mod:`asyncio` does not support legacy generator-based coroutines.
+  (Contributed by Kumar Aditya in :gh:`102748`.)
+
 inspect
 -------
 
index 7fda0e449d500a05340f8b74ea43120b980f5961..ab4f30eb51ba2c6083f6254d631c41f0671aaf60 100644 (file)
@@ -25,8 +25,7 @@ def iscoroutinefunction(func):
 
 # Prioritize native coroutine check to speed-up
 # asyncio.iscoroutine.
-_COROUTINE_TYPES = (types.CoroutineType, types.GeneratorType,
-                    collections.abc.Coroutine)
+_COROUTINE_TYPES = (types.CoroutineType, collections.abc.Coroutine)
 _iscoroutine_typecache = set()
 
 
index f833f788dcb98f94fb49efb50dfd5511bb96f3f6..dc25a46985e3497e791b92099433e938f93b703c 100644 (file)
@@ -119,6 +119,12 @@ class CoroutineTests(BaseTest):
 
         self.assertTrue(asyncio.iscoroutine(FakeCoro()))
 
+    def test_iscoroutine_generator(self):
+        def foo(): yield
+
+        self.assertFalse(asyncio.iscoroutine(foo()))
+
+
     def test_iscoroutinefunction(self):
         async def foo(): pass
         self.assertTrue(asyncio.iscoroutinefunction(foo))
diff --git a/Misc/NEWS.d/next/Library/2023-03-16-08-17-29.gh-issue-102748.WNACpI.rst b/Misc/NEWS.d/next/Library/2023-03-16-08-17-29.gh-issue-102748.WNACpI.rst
new file mode 100644 (file)
index 0000000..b1dc67f
--- /dev/null
@@ -0,0 +1,3 @@
+:func:`asyncio.iscoroutine` now returns ``False`` for generators as
+:mod:`asyncio` does not support legacy generator-based coroutines.
+Patch by Kumar Aditya.