8000 bpo-40979: refactored typing.rst; same content, new sub-sections and ordering by ramalho · Pull Request #21574 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40979: refactored typing.rst; same content, new sub-sections and ordering #21574

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

Merged
merged 20 commits into from
Aug 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
30570c9
refactored typing.rst, see Issue40979
ramalho Jul 21, 2020
1ad12cc
bpo-40979: undo changes to go section-by-section
ramalho Jul 21, 2020
c06142b
bpo-40979: 'Aliases and constants' section
ramalho Jul 21, 2020
7f5d48d
bpo-40979: 'Functions and decorators' section
ramalho Jul 21, 2020
7fb3d72
bpo-40979: 'Generic concrete collections' section
ramalho Jul 21, 2020
b548112
bpo-40979: 'Protocols' section
ramalho Jul 21, 2020
d52afa8
bpo-40979: 'Special typing primitives' section
ramalho Jul 21, 2020
49d2a31
bpo-40979: 'Generic ABCs' section (initial A)
ramalho Jul 21, 2020
bb07243
bpo-40979: 'Generic ABCs' section (initials A to H)
ramalho Jul 21, 2020
5d7c120
bpo-40979: 'Generic ABCs' section (initials A to K)
ramalho Jul 21, 2020
c7358d7
bpo-40979: 'Generic ABCs' section (complete)
ramalho Jul 21, 2020
5ab2f2f
bpo-40979: reordering 'Text' entry in 'Aliases and constants'
ramalho Jul 21, 2020
a7528e3
bpo-40979: small markup fixes
ramalho Jul 21, 2020
2e25885
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 21, 2020
006238b
Merge remote-tracking branch 'upstream/master'
ramalho Aug 1, 2020
9c7b89c
Merge branch 'master' of github.com:ramalho/cpython
ramalho Aug 1, 2020
4505bbb
bpo-40979: sub-sections in Special Types per https://github.com/pytho…
ramalho Aug 1, 2020
cd6e8ea
bpo-40979: further reordering after first review
ramalho Aug 2, 2020
826340a
bpo-40979: reordering after second review
ramalho Aug 2, 2020
7273e95
bpo-40979: added PEP 585 deprecation notes
ramalho Aug 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-40979: 'Generic ABCs' section (initial A)
  • Loading branch information
ramalho committed Jul 21, 2020
commit 49d2a314e69b51a0c0c21875c12d23640dac24bb
127 changes: 65 additions & 62 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,71 @@ Functions and decorators
Note that returning instances of private classes is not recommended.
It is usually preferable to make such classes public.

Generic ABCs (with initial A)
.............................

.. class:: AbstractSet(Sized, Collection[T_co])

A generic version of :class:`collections.abc.Set`.

.. class:: AsyncContextManager(Generic[T_co])

A generic version of :class:`contextlib.AbstractAsyncContextManager`.

.. versionadded:: 3.5.4
.. versionadded:: 3.6.2

.. class:: AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra])

An async generator can be annotated by the generic type
``AsyncGenerator[YieldType, SendType]``. For example::

async def echo_round() -> AsyncGenerator[int, float]:
sent = yield 0
while sent >= 0.0:
rounded = await round(sent)
sent = yield rounded

Unlike normal generators, async generators cannot return a value, so there
is no ``ReturnType`` type parameter. As with :class:`Generator`, the
``SendType`` behaves contravariantly.

If your generator will only yield values, set the ``SendType`` to
``None``::

async def infinite_stream(start: int) -> AsyncGenerator[int, None]:
while True:
yield start
start = await increment(start)

Alternatively, annotate your generator as having a return type of
either ``AsyncIterable[YieldType]`` or ``AsyncIterator[YieldType]``::

async def infinite_stream(start: int) -> AsyncIterator[int]:
while True:
yield start
start = await increment(start)

.. versionadded:: 3.6.1

.. class:: AsyncIterable(Generic[T_co])

A generic version of :class:`collections.abc.AsyncIterable`.

.. versionadded:: 3.5.2

.. class:: AsyncIterator(AsyncIterable[T_co])

A generic version of :class:`collections.abc.AsyncIterator`.

.. versionadded:: 3.5.2

.. class:: Awaitable(Generic[T_co])

A generic version of :class:`collections.abc.Awaitable`.

.. versionadded:: 3.5.2

Remaining classes, functions and decorators
...........................................

Expand Down Expand Up @@ -1320,10 +1385,6 @@ Remaining classes, functions and decorators

.. versionadded:: 3.6.0

.. class:: AbstractSet(Sized, Collection[T_co])

A generic version of :class:`collections.abc.Set`.

.. class:: MutableSet(AbstractSet[T])

A generic version of :class:`collections.abc.MutableSet`.
Expand Down Expand Up @@ -1374,12 +1435,6 @@ Remaining classes, functions and decorators

A generic version of :class:`collections.abc.ValuesView`.

.. class:: Awaitable(Generic[T_co])

A generic version of :class:`collections.abc.Awaitable`.

.. versionadded:: 3.5.2

.. class:: Coroutine(Awaitable[V_co], Generic[T_co T_contra, V_co])

A generic version of :class:`collections.abc.Coroutine`.
Expand All @@ -1395,32 +1450,13 @@ Remaining classes, functions and decorators

.. versionadded:: 3.5.3

.. class:: AsyncIterable(Generic[T_co])

A generic version of :class:`collections.abc.AsyncIterable`.

.. versionadded:: 3.5.2

.. class:: AsyncIterator(AsyncIterable[T_co])

A generic version of :class:`collections.abc.AsyncIterator`.

.. versionadded:: 3.5.2

.. class:: ContextManager(Generic[T_co])

A generic version of :class:`contextlib.AbstractContextManager`.

.. versionadded:: 3.5.4
.. versionadded:: 3.6.0

.. class:: AsyncContextManager(Generic[T_co])

A generic version of :class:`contextlib.AbstractAsyncContextManager`.

.. versionadded:: 3.5.4
.. versionadded:: 3.6.2

.. class:: Generator(Iterator[T_co], Generic[T_co, T_contra, V_co])

A generator can be annotated by the generic type
Expand Down Expand Up @@ -1452,39 +1488,6 @@ Remaining classes, functions and decorators
yield start
start += 1

.. class:: AsyncGenerator(AsyncIterator[T_co], Generic[T_co, T_contra])

An async generator can be annotated by the generic type
``AsyncGenerator[YieldType, SendType]``. For example::

async def echo_round() -> AsyncGenerator[int, float]:
sent = yield 0
while sent >= 0.0:
rounded = await round(sent)
sent = yield rounded

Unlike normal generators, async generators cannot return a value, so there
is no ``ReturnType`` type parameter. As with :class:`Generator`, the
``SendType`` behaves contravariantly.

If your generator will only yield values, set the ``SendType`` to
``None``::

async def infinite_stream(start: int) -> AsyncGenerator[int, None]:
while True:
yield start
start = await increment(start)

Alternatively, annotate your generator as having a return type of
either ``AsyncIterable[YieldType]`` or ``AsyncIterator[YieldType]``::

async def infinite_stream(start: int) -> AsyncIterator[int]:
while True:
yield start
start = await increment(start)

.. versionadded:: 3.6.1

.. class:: IO
TextIO
BinaryIO
Expand Down
0