Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-102748: remove legacy support for generator based coroutines from asyncio.iscoroutine #102749

Merged
merged 8 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 :const:`False` for generators as
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
:mod:`asyncio` does not supports legacy generator-based coroutines.
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
(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 :const:`False` for generators as
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
:mod:`asyncio` does not supports legacy generator-based coroutines.
kumaraditya303 marked this conversation as resolved.
Show resolved Hide resolved
Patch by Kumar Aditya.