Skip to content

Commit 54868be

Browse files
ilevkivskyigvanrossum
authored andcommitted
Document that async generators and comprehensions are supported (#3271)
1 parent 088e7e3 commit 54868be

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

docs/source/python36.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ New features in Python 3.6
55

66
Python 3.6 was `released
77
<https://www.python.org/downloads/release/python-360/>`_ in
8-
December 2016. As of mypy 0.500 most language features new in Python
9-
3.6 are supported, with the exception of asynchronous generators and
10-
comprehensions.
8+
December 2016. As of mypy 0.510 all language features new in Python
9+
3.6 are supported.
1110

1211
Syntax for variable annotations (`PEP 526 <https://www.python.org/dev/peps/pep-0526>`_)
1312
---------------------------------------------------------------------------------------
@@ -50,22 +49,20 @@ Mypy fully supports this syntax:
5049
hexes: List[int] = []
5150
hexes.append(0x_FF_FF_FF_FF)
5251
53-
Asynchronous generators (`PEP 525 <https://www.python.org/dev/peps/pep-0525>`_)
54-
-------------------------------------------------------------------------------
52+
Asynchronous generators (`PEP 525 <https://www.python.org/dev/peps/pep-0525>`_) and comprehensions (`PEP 530 <https://www.python.org/dev/peps/pep-0530>`_)
53+
----------------------------------------------------------------------------------------------------------------------------------------------------------
5554

56-
Python 3.6 feature: coroutines defined with ``async def`` (PEP 492)
57-
can now also be generators, i.e. contain ``yield`` expressions.
55+
Python 3.6 allows coroutines defined with ``async def`` (PEP 492) to be
56+
generators, i.e. contain ``yield`` expressions, and introduces a syntax for
57+
asynchronous comprehensions. Mypy fully supports these features, for example:
5858

59-
Mypy does not yet support this.
60-
61-
Asynchronous comprehensions (`PEP 530 <https://www.python.org/dev/peps/pep-0530>`_)
62-
-----------------------------------------------------------------------------------
59+
.. code-block:: python
6360
64-
Python 3.6 feature: coroutines defined with ``async def`` (PEP 492)
65-
can now also contain list, set and dict comprehensions that use
66-
``async for`` syntax.
61+
from typing import AsyncIterator
6762
68-
Mypy does not yet support this.
63+
async def gen() -> AsyncIterator[bytes]:
64+
lst = [b async for b in gen()] # Inferred type is "List[bytes]"
65+
yield 'no way' # Error: Incompatible types (got "str", expected "bytes")
6966
7067
New named tuple syntax
7168
----------------------

0 commit comments

Comments
 (0)