mirror of
https://github.com/python/cpython.git
synced 2025-11-17 01:25:57 +00:00
bpo-43216: Remove @asyncio.coroutine (GH-26369)
Remove the @asyncio.coroutine decorator enabling legacy generator-based coroutines to be compatible with async/await code; remove asyncio.coroutines.CoroWrapper used for wrapping legacy coroutine objects in the debug mode. The decorator has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10.
This commit is contained in:
parent
3623aaa78c
commit
a1092f6249
11 changed files with 85 additions and 763 deletions
|
|
@ -148,9 +148,6 @@ other coroutines::
|
|||
* a *coroutine object*: an object returned by calling a
|
||||
*coroutine function*.
|
||||
|
||||
asyncio also supports legacy :ref:`generator-based
|
||||
<asyncio_generator_based_coro>` coroutines.
|
||||
|
||||
|
||||
.. rubric:: Tasks
|
||||
|
||||
|
|
@ -1042,60 +1039,3 @@ Task Object
|
|||
in the :func:`repr` output of a task object.
|
||||
|
||||
.. versionadded:: 3.8
|
||||
|
||||
|
||||
.. _asyncio_generator_based_coro:
|
||||
|
||||
Generator-based Coroutines
|
||||
==========================
|
||||
|
||||
.. note::
|
||||
|
||||
Support for generator-based coroutines is **deprecated** and
|
||||
is scheduled for removal in Python 3.10.
|
||||
|
||||
Generator-based coroutines predate async/await syntax. They are
|
||||
Python generators that use ``yield from`` expressions to await
|
||||
on Futures and other coroutines.
|
||||
|
||||
Generator-based coroutines should be decorated with
|
||||
:func:`@asyncio.coroutine <asyncio.coroutine>`, although this is not
|
||||
enforced.
|
||||
|
||||
|
||||
.. decorator:: coroutine
|
||||
|
||||
Decorator to mark generator-based coroutines.
|
||||
|
||||
This decorator enables legacy generator-based coroutines to be
|
||||
compatible with async/await code::
|
||||
|
||||
@asyncio.coroutine
|
||||
def old_style_coroutine():
|
||||
yield from asyncio.sleep(1)
|
||||
|
||||
async def main():
|
||||
await old_style_coroutine()
|
||||
|
||||
This decorator should not be used for :keyword:`async def`
|
||||
coroutines.
|
||||
|
||||
.. deprecated-removed:: 3.8 3.10
|
||||
|
||||
Use :keyword:`async def` instead.
|
||||
|
||||
.. function:: iscoroutine(obj)
|
||||
|
||||
Return ``True`` if *obj* is a :ref:`coroutine object <coroutine>`.
|
||||
|
||||
This method is different from :func:`inspect.iscoroutine` because
|
||||
it returns ``True`` for generator-based coroutines.
|
||||
|
||||
.. function:: iscoroutinefunction(func)
|
||||
|
||||
Return ``True`` if *func* is a :ref:`coroutine function
|
||||
<coroutine>`.
|
||||
|
||||
This method is different from :func:`inspect.iscoroutinefunction`
|
||||
because it returns ``True`` for generator-based coroutine functions
|
||||
decorated with :func:`@coroutine <coroutine>`.
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ ABC Inherits from Abstract Methods Mixin
|
|||
|
||||
.. note::
|
||||
In CPython, generator-based coroutines (generators decorated with
|
||||
:func:`types.coroutine` or :func:`asyncio.coroutine`) are
|
||||
:func:`types.coroutine`) are
|
||||
*awaitables*, even though they do not have an :meth:`__await__` method.
|
||||
Using ``isinstance(gencoro, Awaitable)`` for them will return ``False``.
|
||||
Use :func:`inspect.isawaitable` to detect them.
|
||||
|
|
@ -216,7 +216,7 @@ ABC Inherits from Abstract Methods Mixin
|
|||
|
||||
.. note::
|
||||
In CPython, generator-based coroutines (generators decorated with
|
||||
:func:`types.coroutine` or :func:`asyncio.coroutine`) are
|
||||
:func:`types.coroutine`) are
|
||||
*awaitables*, even though they do not have an :meth:`__await__` method.
|
||||
Using ``isinstance(gencoro, Coroutine)`` for them will return ``False``.
|
||||
Use :func:`inspect.isawaitable` to detect them.
|
||||
|
|
|
|||
|
|
@ -2714,7 +2714,7 @@ are awaitable.
|
|||
.. note::
|
||||
|
||||
The :term:`generator iterator` objects returned from generators
|
||||
decorated with :func:`types.coroutine` or :func:`asyncio.coroutine`
|
||||
decorated with :func:`types.coroutine`
|
||||
are also awaitable, but they do not implement :meth:`__await__`.
|
||||
|
||||
.. method:: object.__await__(self)
|
||||
|
|
|
|||
|
|
@ -171,7 +171,15 @@ Deprecated
|
|||
Removed
|
||||
=======
|
||||
|
||||
* The :func:`@asyncio.coroutine <asyncio.coroutine>` :term:`decorator` enabling
|
||||
legacy generator-based coroutines to be compatible with async/await code.
|
||||
The function has been deprecated since Python 3.8 and the removal was
|
||||
initially scheduled for Python 3.10. Use :keyword:`async def` instead.
|
||||
(Contributed by Illia Volochii in :issue:`43216`.)
|
||||
|
||||
* :class:`asyncio.coroutines.CoroWrapper` used for wrapping legacy
|
||||
generator-based coroutine objects in the debug mode.
|
||||
(Contributed by Illia Volochii in :issue:`43216`.)
|
||||
|
||||
Porting to Python 3.11
|
||||
======================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue