Skip to content

Commit

Permalink
pythonGH-102748: remove legacy support for generator based coroutines…
Browse files Browse the repository at this point in the history
… from `asyncio.iscoroutine` (python#102749)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
2 people authored and Fidget-Spinner committed Mar 27, 2023
1 parent dd97b75 commit a123f26
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
3 changes: 1 addition & 2 deletions Lib/asyncio/coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_asyncio/test_pep492.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ async def foo(): pass

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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit a123f26

Please sign in to comment.