-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Conversation
return (yield from awaitable.__await__()) | ||
|
||
_wrap_awaitable._is_coroutine = _is_coroutine | ||
return await awaitable |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
Lib/asyncio/coroutines.py
Outdated
return (inspect.iscoroutinefunction(func) or | ||
getattr(func, '_is_coroutine', None) is _is_coroutine) | ||
"""Alias for inspect.iscoroutinefunction.""" | ||
warnings._deprecated("asyncio.iscoroutinefunction", remove=(3, 14)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @hugovk for removals
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
2f61137
to
5402f43
Compare
asyncio.iscoroutinefunction
a deprecated alias ofinspect.iscoroutinefunction
and removeasyncio.coroutines._is_coroutine
#94912