diff options
author | Yury Selivanov <yury@magic.io> | 2017-10-06 06:08:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-06 06:08:57 (GMT) |
commit | faa135acbfcd55f79fb97f7525c8aa6f5a5b6a22 (patch) | |
tree | 8fd008b849b322699e20e18f92a179c06f7b0580 /Doc | |
parent | 86566702f311f8e90600e85350f6b6769a384ea5 (diff) | |
download | cpython-faa135acbfcd55f79fb97f7525c8aa6f5a5b6a22.zip cpython-faa135acbfcd55f79fb97f7525c8aa6f5a5b6a22.tar.gz cpython-faa135acbfcd55f79fb97f7525c8aa6f5a5b6a22.tar.bz2 |
bpo-31709: Drop support for asynchronous __aiter__. (#3903)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/reference/datamodel.rst | 53 |
1 files changed, 9 insertions, 44 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 31a7671..153b58b 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2520,9 +2520,8 @@ generators, coroutines do not directly support iteration. Asynchronous Iterators ---------------------- -An *asynchronous iterable* is able to call asynchronous code in its -``__aiter__`` implementation, and an *asynchronous iterator* can call -asynchronous code in its ``__anext__`` method. +An *asynchronous iterator* can call asynchronous code in +its ``__anext__`` method. Asynchronous iterators can be used in an :keyword:`async for` statement. @@ -2552,48 +2551,14 @@ An example of an asynchronous iterable object:: .. versionadded:: 3.5 -.. note:: +.. versionchanged:: 3.7 + Prior to Python 3.7, ``__aiter__`` could return an *awaitable* + that would resolve to an + :term:`asynchronous iterator <asynchronous iterator>`. - .. versionchanged:: 3.5.2 - Starting with CPython 3.5.2, ``__aiter__`` can directly return - :term:`asynchronous iterators <asynchronous iterator>`. Returning - an :term:`awaitable` object will result in a - :exc:`PendingDeprecationWarning`. - - The recommended way of writing backwards compatible code in - CPython 3.5.x is to continue returning awaitables from - ``__aiter__``. If you want to avoid the PendingDeprecationWarning - and keep the code backwards compatible, the following decorator - can be used:: - - import functools - import sys - - if sys.version_info < (3, 5, 2): - def aiter_compat(func): - @functools.wraps(func) - async def wrapper(self): - return func(self) - return wrapper - else: - def aiter_compat(func): - return func - - Example:: - - class AsyncIterator: - - @aiter_compat - def __aiter__(self): - return self - - async def __anext__(self): - ... - - Starting with CPython 3.6, the :exc:`PendingDeprecationWarning` - will be replaced with the :exc:`DeprecationWarning`. - In CPython 3.7, returning an awaitable from ``__aiter__`` will - result in a :exc:`RuntimeError`. + Starting with Python 3.7, ``__aiter__`` must return an + asynchronous iterator object. Returning anything else + will result in a :exc:`TypeError` error. .. _async-context-managers: |