@@ -2433,6 +2433,18 @@ These protocols are decorated with :func:`runtime_checkable`.
24332433 An ABC with one abstract method ``__round__ ``
24342434 that is covariant in its return type.
24352435
2436+ ABCs for working with IO
2437+ ------------------------
2438+
2439+ .. class :: IO
2440+ TextIO
2441+ BinaryIO
2442+
2443+ Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
2444+ and ``BinaryIO(IO[bytes]) ``
2445+ represent the types of I/O streams such as returned by
2446+ :func: `open `.
2447+
24362448Functions and decorators
24372449------------------------
24382450
@@ -3052,11 +3064,15 @@ Constant
30523064
30533065 .. versionadded :: 3.5.2
30543066
3055- Generic concrete collections
3056- ----------------------------
3067+ .. _generic-concrete-collections :
30573068
3058- Corresponding to built-in types
3059- """""""""""""""""""""""""""""""
3069+ Deprecated aliases
3070+ ------------------
3071+
3072+ .. _corresponding-to-built-in-types :
3073+
3074+ Aliases to built-in types
3075+ """""""""""""""""""""""""
30603076
30613077.. class :: Dict(dict, MutableMapping[KT, VT])
30623078
@@ -3118,8 +3134,10 @@ Corresponding to built-in types
31183134
31193135.. note :: :data:`Tuple` is a special form.
31203136
3121- Corresponding to types in :mod: `collections `
3122- """"""""""""""""""""""""""""""""""""""""""""
3137+ .. _corresponding-to-types-in-collections :
3138+
3139+ Aliases to types in :mod: `collections `
3140+ """"""""""""""""""""""""""""""""""""""
31233141
31243142.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
31253143
@@ -3174,17 +3192,10 @@ Corresponding to types in :mod:`collections`
31743192 :class: `collections.deque ` now supports subscripting (``[] ``).
31753193 See :pep: `585 ` and :ref: `types-genericalias `.
31763194
3177- Other concrete types
3178- """"""""""""""""""""
3195+ .. _other-concrete-types :
31793196
3180- .. class :: IO
3181- TextIO
3182- BinaryIO
3183-
3184- Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
3185- and ``BinaryIO(IO[bytes]) ``
3186- represent the types of I/O streams such as returned by
3187- :func: `open `.
3197+ Aliases to other concrete types
3198+ """""""""""""""""""""""""""""""
31883199
31893200.. class :: Pattern
31903201 Match
@@ -3223,11 +3234,11 @@ Other concrete types
32233234 currently planned, but users are encouraged to use
32243235 :class: `str ` instead of ``Text ``.
32253236
3226- Abstract Base Classes
3227- ---------------------
3237+ .. _ abstract-base-classes :
3238+ .. _ corresponding-to-collections-in-collections-abc :
32283239
3229- Corresponding to collections in :mod: `collections.abc `
3230- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3240+ Aliases to container ABCs in :mod: `collections.abc `
3241+ """""""""""""""""""""""""""""""""""""""""""""""""""
32313242
32323243.. class :: AbstractSet(Collection[T_co])
32333244
@@ -3342,86 +3353,10 @@ Corresponding to collections in :mod:`collections.abc`
33423353 :class: `collections.abc.ValuesView ` now supports subscripting (``[] ``).
33433354 See :pep: `585 ` and :ref: `types-genericalias `.
33443355
3345- Corresponding to other types in :mod: `collections.abc `
3346- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3347-
3348- .. class :: Iterable(Generic[T_co])
3349-
3350- Deprecated alias to :class: `collections.abc.Iterable `.
3351-
3352- .. deprecated :: 3.9
3353- :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3354- See :pep: `585 ` and :ref: `types-genericalias `.
3355-
3356- .. class :: Iterator(Iterable[T_co])
3357-
3358- Deprecated alias to :class: `collections.abc.Iterator `.
3359-
3360- .. deprecated :: 3.9
3361- :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3362- See :pep: `585 ` and :ref: `types-genericalias `.
3363-
3364- .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3365-
3366- Deprecated alias to :class: `collections.abc.Generator `.
3367-
3368- A generator can be annotated by the generic type
3369- ``Generator[YieldType, SendType, ReturnType] ``. For example::
3370-
3371- def echo_round() -> Generator[int, float, str]:
3372- sent = yield 0
3373- while sent >= 0:
3374- sent = yield round(sent)
3375- return 'Done'
3376-
3377- Note that unlike many other generics in the typing module, the ``SendType ``
3378- of :class: `Generator ` behaves contravariantly, not covariantly or
3379- invariantly.
3380-
3381- If your generator will only yield values, set the ``SendType `` and
3382- ``ReturnType `` to ``None ``::
3383-
3384- def infinite_stream(start: int) -> Generator[int, None, None]:
3385- while True:
3386- yield start
3387- start += 1
3388-
3389- Alternatively, annotate your generator as having a return type of
3390- either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3391-
3392- def infinite_stream(start: int) -> Iterator[int]:
3393- while True:
3394- yield start
3395- start += 1
3396-
3397- .. deprecated :: 3.9
3398- :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3399- See :pep: `585 ` and :ref: `types-genericalias `.
3400-
3401- .. class :: Hashable
3402-
3403- Deprecated alias to :class: `collections.abc.Hashable `.
3404-
3405- .. deprecated :: 3.12
3406- Use :class: `collections.abc.Hashable ` directly instead.
3407-
3408- .. class :: Reversible(Iterable[T_co])
3409-
3410- Deprecated alias to :class: `collections.abc.Reversible `.
3356+ .. _asynchronous-programming :
34113357
3412- .. deprecated :: 3.9
3413- :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3414- See :pep: `585 ` and :ref: `types-genericalias `.
3415-
3416- .. class :: Sized
3417-
3418- Deprecated alias to :class: `collections.abc.Sized `.
3419-
3420- .. deprecated :: 3.12
3421- Use :class: `collections.abc.Sized ` directly instead.
3422-
3423- Asynchronous programming
3424- """"""""""""""""""""""""
3358+ Aliases to asynchronous ABCs in :mod: `collections.abc `
3359+ """"""""""""""""""""""""""""""""""""""""""""""""""""""
34253360
34263361.. class :: Coroutine(Awaitable[ReturnType], Generic[YieldType, SendType, ReturnType])
34273362
@@ -3512,9 +3447,90 @@ Asynchronous programming
35123447 :class: `collections.abc.Awaitable ` now supports subscripting (``[] ``).
35133448 See :pep: `585 ` and :ref: `types-genericalias `.
35143449
3450+ .. _corresponding-to-other-types-in-collections-abc :
3451+
3452+ Aliases to other ABCs in :mod: `collections.abc `
3453+ """""""""""""""""""""""""""""""""""""""""""""""
3454+
3455+ .. class :: Iterable(Generic[T_co])
3456+
3457+ Deprecated alias to :class: `collections.abc.Iterable `.
3458+
3459+ .. deprecated :: 3.9
3460+ :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3461+ See :pep: `585 ` and :ref: `types-genericalias `.
3462+
3463+ .. class :: Iterator(Iterable[T_co])
3464+
3465+ Deprecated alias to :class: `collections.abc.Iterator `.
3466+
3467+ .. deprecated :: 3.9
3468+ :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3469+ See :pep: `585 ` and :ref: `types-genericalias `.
3470+
3471+ .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3472+
3473+ Deprecated alias to :class: `collections.abc.Generator `.
3474+
3475+ A generator can be annotated by the generic type
3476+ ``Generator[YieldType, SendType, ReturnType] ``. For example::
3477+
3478+ def echo_round() -> Generator[int, float, str]:
3479+ sent = yield 0
3480+ while sent >= 0:
3481+ sent = yield round(sent)
3482+ return 'Done'
3483+
3484+ Note that unlike many other generics in the typing module, the ``SendType ``
3485+ of :class: `Generator ` behaves contravariantly, not covariantly or
3486+ invariantly.
3487+
3488+ If your generator will only yield values, set the ``SendType `` and
3489+ ``ReturnType `` to ``None ``::
3490+
3491+ def infinite_stream(start: int) -> Generator[int, None, None]:
3492+ while True:
3493+ yield start
3494+ start += 1
3495+
3496+ Alternatively, annotate your generator as having a return type of
3497+ either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3498+
3499+ def infinite_stream(start: int) -> Iterator[int]:
3500+ while True:
3501+ yield start
3502+ start += 1
3503+
3504+ .. deprecated :: 3.9
3505+ :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3506+ See :pep: `585 ` and :ref: `types-genericalias `.
3507+
3508+ .. class :: Hashable
3509+
3510+ Deprecated alias to :class: `collections.abc.Hashable `.
3511+
3512+ .. deprecated :: 3.12
3513+ Use :class: `collections.abc.Hashable ` directly instead.
3514+
3515+ .. class :: Reversible(Iterable[T_co])
3516+
3517+ Deprecated alias to :class: `collections.abc.Reversible `.
3518+
3519+ .. deprecated :: 3.9
3520+ :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3521+ See :pep: `585 ` and :ref: `types-genericalias `.
3522+
3523+ .. class :: Sized
3524+
3525+ Deprecated alias to :class: `collections.abc.Sized `.
3526+
3527+ .. deprecated :: 3.12
3528+ Use :class: `collections.abc.Sized ` directly instead.
3529+
3530+ .. _context-manager-types :
35153531
3516- Context manager types
3517- """""""""""""""""""""
3532+ Aliases to :mod: ` contextlib ` ABCs
3533+ """""""""""""""""""""""""""""""""
35183534
35193535.. class :: ContextManager(Generic[T_co])
35203536
0 commit comments