@@ -2159,6 +2159,18 @@ These protocols are decorated with :func:`runtime_checkable`.
21592159 An ABC with one abstract method ``__round__ ``
21602160 that is covariant in its return type.
21612161
2162+ ABCs for working with IO
2163+ ------------------------
2164+
2165+ .. class :: IO
2166+ TextIO
2167+ BinaryIO
2168+
2169+ Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
2170+ and ``BinaryIO(IO[bytes]) ``
2171+ represent the types of I/O streams such as returned by
2172+ :func: `open `.
2173+
21622174Functions and decorators
21632175------------------------
21642176
@@ -2699,11 +2711,15 @@ Constant
26992711
27002712 .. versionadded :: 3.5.2
27012713
2702- Generic concrete collections
2703- ----------------------------
2714+ .. _generic-concrete-collections :
27042715
2705- Corresponding to built-in types
2706- """""""""""""""""""""""""""""""
2716+ Deprecated aliases
2717+ ------------------
2718+
2719+ .. _corresponding-to-built-in-types :
2720+
2721+ Aliases to built-in types
2722+ """""""""""""""""""""""""
27072723
27082724.. class :: Dict(dict, MutableMapping[KT, VT])
27092725
@@ -2767,8 +2783,10 @@ Corresponding to built-in types
27672783
27682784.. note :: :data:`Tuple` is a special form.
27692785
2770- Corresponding to types in :mod: `collections `
2771- """"""""""""""""""""""""""""""""""""""""""""
2786+ .. _corresponding-to-types-in-collections :
2787+
2788+ Aliases to types in :mod: `collections `
2789+ """"""""""""""""""""""""""""""""""""""
27722790
27732791.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
27742792
@@ -2823,21 +2841,10 @@ Corresponding to types in :mod:`collections`
28232841 :class: `collections.deque ` now supports subscripting (``[] ``).
28242842 See :pep: `585 ` and :ref: `types-genericalias `.
28252843
2826- Other concrete types
2827- """"""""""""""""""""
2844+ .. _other-concrete-types :
28282845
2829- .. class :: IO
2830- TextIO
2831- BinaryIO
2832-
2833- Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
2834- and ``BinaryIO(IO[bytes]) ``
2835- represent the types of I/O streams such as returned by
2836- :func: `open `.
2837-
2838- .. deprecated-removed :: 3.8 3.13
2839- The ``typing.io `` namespace is deprecated and will be removed.
2840- These types should be directly imported from ``typing `` instead.
2846+ Aliases to other concrete types
2847+ """""""""""""""""""""""""""""""
28412848
28422849.. class :: Pattern
28432850 Match
@@ -2880,11 +2887,11 @@ Other concrete types
28802887 currently planned, but users are encouraged to use
28812888 :class: `str ` instead of ``Text ``.
28822889
2883- Abstract Base Classes
2884- ---------------------
2890+ .. _ abstract-base-classes :
2891+ .. _ corresponding-to-collections-in-collections-abc :
28852892
2886- Corresponding to collections in :mod: `collections.abc `
2887- """"""""""""""""""""""""""""""""""""""""""""""""""""""
2893+ Aliases to container ABCs in :mod: `collections.abc `
2894+ """""""""""""""""""""""""""""""""""""""""""""""""""
28882895
28892896.. class :: AbstractSet(Collection[T_co])
28902897
@@ -2999,80 +3006,10 @@ Corresponding to collections in :mod:`collections.abc`
29993006 :class: `collections.abc.ValuesView ` now supports subscripting (``[] ``).
30003007 See :pep: `585 ` and :ref: `types-genericalias `.
30013008
3002- Corresponding to other types in :mod: `collections.abc `
3003- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3004-
3005- .. class :: Iterable(Generic[T_co])
3006-
3007- Deprecated alias to :class: `collections.abc.Iterable `.
3008-
3009- .. deprecated :: 3.9
3010- :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3011- See :pep: `585 ` and :ref: `types-genericalias `.
3012-
3013- .. class :: Iterator(Iterable[T_co])
3014-
3015- Deprecated alias to :class: `collections.abc.Iterator `.
3016-
3017- .. deprecated :: 3.9
3018- :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3019- See :pep: `585 ` and :ref: `types-genericalias `.
3020-
3021- .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3022-
3023- Deprecated alias to :class: `collections.abc.Generator `.
3024-
3025- A generator can be annotated by the generic type
3026- ``Generator[YieldType, SendType, ReturnType] ``. For example::
3027-
3028- def echo_round() -> Generator[int, float, str]:
3029- sent = yield 0
3030- while sent >= 0:
3031- sent = yield round(sent)
3032- return 'Done'
3033-
3034- Note that unlike many other generics in the typing module, the ``SendType ``
3035- of :class: `Generator ` behaves contravariantly, not covariantly or
3036- invariantly.
3037-
3038- If your generator will only yield values, set the ``SendType `` and
3039- ``ReturnType `` to ``None ``::
3040-
3041- def infinite_stream(start: int) -> Generator[int, None, None]:
3042- while True:
3043- yield start
3044- start += 1
3045-
3046- Alternatively, annotate your generator as having a return type of
3047- either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3048-
3049- def infinite_stream(start: int) -> Iterator[int]:
3050- while True:
3051- yield start
3052- start += 1
3053-
3054- .. deprecated :: 3.9
3055- :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3056- See :pep: `585 ` and :ref: `types-genericalias `.
3057-
3058- .. class :: Hashable
3059-
3060- Alias to :class: `collections.abc.Hashable `.
3061-
3062- .. class :: Reversible(Iterable[T_co])
3063-
3064- Deprecated alias to :class: `collections.abc.Reversible `.
3065-
3066- .. deprecated :: 3.9
3067- :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3068- See :pep: `585 ` and :ref: `types-genericalias `.
3069-
3070- .. class :: Sized
3071-
3072- Alias to :class: `collections.abc.Sized `.
3009+ .. _asynchronous-programming :
30733010
3074- Asynchronous programming
3075- """"""""""""""""""""""""
3011+ Aliases to asynchronous ABCs in :mod: ` collections.abc `
3012+ """"""""""""""""""""""""""""""""""""""""""""""""""""""
30763013
30773014.. class :: Coroutine(Awaitable[ReturnType], Generic[YieldType, SendType, ReturnType])
30783015
@@ -3163,9 +3100,84 @@ Asynchronous programming
31633100 :class: `collections.abc.Awaitable ` now supports subscripting (``[] ``).
31643101 See :pep: `585 ` and :ref: `types-genericalias `.
31653102
3103+ .. _corresponding-to-other-types-in-collections-abc :
3104+
3105+ Aliases to other ABCs in :mod: `collections.abc `
3106+ """""""""""""""""""""""""""""""""""""""""""""""
3107+
3108+ .. class :: Iterable(Generic[T_co])
3109+
3110+ Deprecated alias to :class: `collections.abc.Iterable `.
3111+
3112+ .. deprecated :: 3.9
3113+ :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3114+ See :pep: `585 ` and :ref: `types-genericalias `.
3115+
3116+ .. class :: Iterator(Iterable[T_co])
3117+
3118+ Deprecated alias to :class: `collections.abc.Iterator `.
3119+
3120+ .. deprecated :: 3.9
3121+ :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3122+ See :pep: `585 ` and :ref: `types-genericalias `.
3123+
3124+ .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3125+
3126+ Deprecated alias to :class: `collections.abc.Generator `.
3127+
3128+ A generator can be annotated by the generic type
3129+ ``Generator[YieldType, SendType, ReturnType] ``. For example::
3130+
3131+ def echo_round() -> Generator[int, float, str]:
3132+ sent = yield 0
3133+ while sent >= 0:
3134+ sent = yield round(sent)
3135+ return 'Done'
3136+
3137+ Note that unlike many other generics in the typing module, the ``SendType ``
3138+ of :class: `Generator ` behaves contravariantly, not covariantly or
3139+ invariantly.
3140+
3141+ If your generator will only yield values, set the ``SendType `` and
3142+ ``ReturnType `` to ``None ``::
3143+
3144+ def infinite_stream(start: int) -> Generator[int, None, None]:
3145+ while True:
3146+ yield start
3147+ start += 1
3148+
3149+ Alternatively, annotate your generator as having a return type of
3150+ either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3151+
3152+ def infinite_stream(start: int) -> Iterator[int]:
3153+ while True:
3154+ yield start
3155+ start += 1
3156+
3157+ .. deprecated :: 3.9
3158+ :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3159+ See :pep: `585 ` and :ref: `types-genericalias `.
3160+
3161+ .. class :: Hashable
3162+
3163+ Alias to :class: `collections.abc.Hashable `.
3164+
3165+ .. class :: Reversible(Iterable[T_co])
3166+
3167+ Deprecated alias to :class: `collections.abc.Reversible `.
3168+
3169+ .. deprecated :: 3.9
3170+ :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3171+ See :pep: `585 ` and :ref: `types-genericalias `.
3172+
3173+ .. class :: Sized
3174+
3175+ Alias to :class: `collections.abc.Sized `.
3176+
3177+ .. _context-manager-types :
31663178
3167- Context manager types
3168- """""""""""""""""""""
3179+ Aliases to :mod: ` contextlib ` ABCs
3180+ """""""""""""""""""""""""""""""""
31693181
31703182.. class :: ContextManager(Generic[T_co])
31713183
0 commit comments