Skip to content

Commit a123f26

Browse files
kumaraditya303AlexWaygood
authored andcommitted
pythonGH-102748: remove legacy support for generator based coroutines from asyncio.iscoroutine (python#102749)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent dd97b75 commit a123f26

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Doc/whatsnew/3.12.rst

+4
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ asyncio
237237
* Add C implementation of :func:`asyncio.current_task` for 4x-6x speedup.
238238
(Contributed by Itamar Ostricher and Pranav Thulasiram Bhat in :gh:`100344`.)
239239

240+
* :func:`asyncio.iscoroutine` now returns ``False`` for generators as
241+
:mod:`asyncio` does not support legacy generator-based coroutines.
242+
(Contributed by Kumar Aditya in :gh:`102748`.)
243+
240244
inspect
241245
-------
242246

Lib/asyncio/coroutines.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def iscoroutinefunction(func):
2525

2626
# Prioritize native coroutine check to speed-up
2727
# asyncio.iscoroutine.
28-
_COROUTINE_TYPES = (types.CoroutineType, types.GeneratorType,
29-
collections.abc.Coroutine)
28+
_COROUTINE_TYPES = (types.CoroutineType, collections.abc.Coroutine)
3029
_iscoroutine_typecache = set()
3130

3231

Lib/test/test_asyncio/test_pep492.py

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ async def foo(): pass
119119

120120
self.assertTrue(asyncio.iscoroutine(FakeCoro()))
121121

122+
def test_iscoroutine_generator(self):
123+
def foo(): yield
124+
125+
self.assertFalse(asyncio.iscoroutine(foo()))
126+
127+
122128
def test_iscoroutinefunction(self):
123129
async def foo(): pass
124130
self.assertTrue(asyncio.iscoroutinefunction(foo))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`asyncio.iscoroutine` now returns ``False`` for generators as
2+
:mod:`asyncio` does not support legacy generator-based coroutines.
3+
Patch by Kumar Aditya.

0 commit comments

Comments
 (0)