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-94912: deprecate asyncio.iscoroutinefunction when it behaves differently to inspect.iscoroutinefunction #94923

Closed
wants to merge 10 commits into from

Conversation

graingert
Copy link
Contributor

@graingert graingert commented Jul 17, 2022

return (yield from awaitable.__await__())

_wrap_awaitable._is_coroutine = _is_coroutine
return await awaitable
Copy link
Contributor Author

@graingert graingert Jul 17, 2022

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:

import asyncio.tasks
import collections.abc
import unittest.mock


@collections.abc.Awaitable.register
class sleep_0:
    def __init__(self):
        self.__await__ = lambda: iter((None, ))


async def _wrap_awaitable(awaitable):
    return await awaitable


async def amain():
    await asyncio.ensure_future(sleep_0())  # this works currently but with the new code:
    with unittest.mock.patch("asyncio.tasks._wrap_awaitable", new=_wrap_awaitable):
        await asyncio.ensure_future(sleep_0())  # it will break
asyncio.run(amain())

if not name.isidentifier():
name = 'funcopy'
context = {'_checksig_': checksig, 'mock': mock}
src = """async def %s(*args, **kwargs):
Copy link
Contributor Author

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
return (inspect.iscoroutinefunction(func) or
getattr(func, '_is_coroutine', None) is _is_coroutine)
"""Alias for inspect.iscoroutinefunction."""
warnings._deprecated("asyncio.iscoroutinefunction", remove=(3, 14))
Copy link
Contributor Author

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
Contributor Author

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
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.

Copy link
Contributor Author

@graingert graingert Jul 18, 2022

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)

name = 'funcopy'
context = {'_checksig_': checksig, 'mock': mock}
src = """async def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
Copy link
Contributor Author

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 graingert force-pushed the asyncio-iscoroutinefunction branch from 2f61137 to 5402f43 Compare July 18, 2022 14:32
@graingert graingert changed the title gh-94912: alias asyncio.iscoroutinefunction to inspect.iscoroutinefunction gh-94912: deprecate asyncio.iscoroutinefunction when it behaves differently to inspect.iscoroutinefunction Jul 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 free to 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