@@ -2159,6 +2159,18 @@ These protocols are decorated with :func:`runtime_checkable`.
2159
2159
An ABC with one abstract method ``__round__ ``
2160
2160
that is covariant in its return type.
2161
2161
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
+
2162
2174
Functions and decorators
2163
2175
------------------------
2164
2176
@@ -2699,11 +2711,15 @@ Constant
2699
2711
2700
2712
.. versionadded :: 3.5.2
2701
2713
2702
- Generic concrete collections
2703
- ----------------------------
2714
+ .. _generic-concrete-collections :
2704
2715
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
+ """""""""""""""""""""""""
2707
2723
2708
2724
.. class :: Dict(dict, MutableMapping[KT, VT])
2709
2725
@@ -2767,8 +2783,10 @@ Corresponding to built-in types
2767
2783
2768
2784
.. note :: :data:`Tuple` is a special form.
2769
2785
2770
- Corresponding to types in :mod: `collections `
2771
- """"""""""""""""""""""""""""""""""""""""""""
2786
+ .. _corresponding-to-types-in-collections :
2787
+
2788
+ Aliases to types in :mod: `collections `
2789
+ """"""""""""""""""""""""""""""""""""""
2772
2790
2773
2791
.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
2774
2792
@@ -2823,21 +2841,10 @@ Corresponding to types in :mod:`collections`
2823
2841
:class: `collections.deque ` now supports subscripting (``[] ``).
2824
2842
See :pep: `585 ` and :ref: `types-genericalias `.
2825
2843
2826
- Other concrete types
2827
- """"""""""""""""""""
2844
+ .. _other-concrete-types :
2828
2845
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
+ """""""""""""""""""""""""""""""
2841
2848
2842
2849
.. class :: Pattern
2843
2850
Match
@@ -2880,11 +2887,11 @@ Other concrete types
2880
2887
currently planned, but users are encouraged to use
2881
2888
:class: `str ` instead of ``Text ``.
2882
2889
2883
- Abstract Base Classes
2884
- ---------------------
2890
+ .. _ abstract-base-classes :
2891
+ .. _ corresponding-to-collections-in-collections-abc :
2885
2892
2886
- Corresponding to collections in :mod: `collections.abc `
2887
- """"""""""""""""""""""""""""""""""""""""""""""""""""""
2893
+ Aliases to container ABCs in :mod: `collections.abc `
2894
+ """""""""""""""""""""""""""""""""""""""""""""""""""
2888
2895
2889
2896
.. class :: AbstractSet(Collection[T_co])
2890
2897
@@ -2999,80 +3006,10 @@ Corresponding to collections in :mod:`collections.abc`
2999
3006
:class: `collections.abc.ValuesView ` now supports subscripting (``[] ``).
3000
3007
See :pep: `585 ` and :ref: `types-genericalias `.
3001
3008
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 :
3073
3010
3074
- Asynchronous programming
3075
- """"""""""""""""""""""""
3011
+ Aliases to asynchronous ABCs in :mod: ` collections.abc `
3012
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""
3076
3013
3077
3014
.. class :: Coroutine(Awaitable[ReturnType], Generic[YieldType, SendType, ReturnType])
3078
3015
@@ -3163,9 +3100,84 @@ Asynchronous programming
3163
3100
:class: `collections.abc.Awaitable ` now supports subscripting (``[] ``).
3164
3101
See :pep: `585 ` and :ref: `types-genericalias `.
3165
3102
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 :
3166
3178
3167
- Context manager types
3168
- """""""""""""""""""""
3179
+ Aliases to :mod: ` contextlib ` ABCs
3180
+ """""""""""""""""""""""""""""""""
3169
3181
3170
3182
.. class :: ContextManager(Generic[T_co])
3171
3183
0 commit comments