Skip to content

gh-94912: deprecate asyncio.iscoroutinefunction when it behaves differently to inspect.iscoroutinefunction - #94923

Closed
graingert wants to merge 10 commits into
python:mainfrom
graingert:asyncio-iscoroutinefunction
Closed

gh-94912: deprecate asyncio.iscoroutinefunction when it behaves differently to inspect.iscoroutinefunction#94923
graingert wants to merge 10 commits into
python:mainfrom
graingert:asyncio-iscoroutinefunction

Conversation

@graingert

@graingertgraingert commented Jul 17, 2022

Copy link
Copy Markdown
Contributor

Comment threadLib/asyncio/tasks.py Outdated

@graingertgraingertJul 17, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will insist on objects being real awaitables rather than virtual awaitables - eg:

importasyncio.tasksimportcollections.abcimportunittest.mock@collections.abc.Awaitable.registerclasssleep_0:
def__init__(self):
self.__await__=lambda: iter((None, ))
asyncdef_wrap_awaitable(awaitable):
returnawaitawaitableasyncdefamain():
awaitasyncio.ensure_future(sleep_0()) # this works currently but with the new code:withunittest.mock.patch("asyncio.tasks._wrap_awaitable", new=_wrap_awaitable):
awaitasyncio.ensure_future(sleep_0()) # it will breakasyncio.run(amain())

Comment threadLib/unittest/mock.py Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to fix #94924

@graingert
graingert marked this pull request as ready for review July 17, 2022 17:24
Comment threadLib/asyncio/coroutines.py Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to do a doc change for this too

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @hugovk for removals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you add it to a 3.14 section like https://docs.python.org/3.12/whatsnew/3.12.html#pending-removal-in-python-3-13 ?

And add a .. deprecated-removed:: 3.12 3.14 to the function in its module rst page.

@graingertgraingertJul 18, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk asyncio.iscoroutinefunction's module rst page was already removed: https://github.com/python/cpython/pull/26369/files#diff-5e9a5bb933b1bd1d6092f7e5adb5c06da7a6792e0597f55f911245acacfce7a7L1025

(oops maybe I shouldn't have approved that PR)

Comment threadLib/unittest/mock.py Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another very subtle change - before the signature was checked when the function was called - and now the signature is checked when the coro is primed, but I think this is a better behavior and worth it to allow inspect.iscoroutinefunction to work

@graingert
graingertforce-pushed the asyncio-iscoroutinefunction branch from 2f61137 to 5402f43CompareJuly 18, 2022 14:32
@graingertgraingert changed the title gh-94912: alias asyncio.iscoroutinefunction to inspect.iscoroutinefunctiongh-94912: deprecate asyncio.iscoroutinefunction when it behaves differently to inspect.iscoroutinefunctionJul 19, 2022
@cjw296
cjw296 removed their request for review June 9, 2023 12:59
@graingert
graingert deleted the asyncio-iscoroutinefunction branch August 11, 2024 18:27
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@graingert@hugovk@bedevere-bot@kumaraditya303