@@ -2420,6 +2420,18 @@ These protocols are decorated with :func:`runtime_checkable`.
2420
2420
An ABC with one abstract method ``__round__ ``
2421
2421
that is covariant in its return type.
2422
2422
2423
+ ABCs for working with IO
2424
+ ------------------------
2425
+
2426
+ .. class :: IO
2427
+ TextIO
2428
+ BinaryIO
2429
+
2430
+ Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
2431
+ and ``BinaryIO(IO[bytes]) ``
2432
+ represent the types of I/O streams such as returned by
2433
+ :func: `open `.
2434
+
2423
2435
Functions and decorators
2424
2436
------------------------
2425
2437
@@ -3007,11 +3019,15 @@ Constant
3007
3019
3008
3020
.. versionadded :: 3.5.2
3009
3021
3010
- Generic concrete collections
3011
- ----------------------------
3022
+ .. _generic-concrete-collections :
3012
3023
3013
- Corresponding to built-in types
3014
- """""""""""""""""""""""""""""""
3024
+ Deprecated aliases
3025
+ ------------------
3026
+
3027
+ .. _corresponding-to-built-in-types :
3028
+
3029
+ Aliases to built-in types
3030
+ """""""""""""""""""""""""
3015
3031
3016
3032
.. class :: Dict(dict, MutableMapping[KT, VT])
3017
3033
@@ -3073,8 +3089,10 @@ Corresponding to built-in types
3073
3089
3074
3090
.. note :: :data:`Tuple` is a special form.
3075
3091
3076
- Corresponding to types in :mod: `collections `
3077
- """"""""""""""""""""""""""""""""""""""""""""
3092
+ .. _corresponding-to-types-in-collections :
3093
+
3094
+ Aliases to types in :mod: `collections `
3095
+ """"""""""""""""""""""""""""""""""""""
3078
3096
3079
3097
.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
3080
3098
@@ -3129,17 +3147,10 @@ Corresponding to types in :mod:`collections`
3129
3147
:class: `collections.deque ` now supports subscripting (``[] ``).
3130
3148
See :pep: `585 ` and :ref: `types-genericalias `.
3131
3149
3132
- Other concrete types
3133
- """"""""""""""""""""
3150
+ .. _other-concrete-types :
3134
3151
3135
- .. class :: IO
3136
- TextIO
3137
- BinaryIO
3138
-
3139
- Generic type ``IO[AnyStr] `` and its subclasses ``TextIO(IO[str]) ``
3140
- and ``BinaryIO(IO[bytes]) ``
3141
- represent the types of I/O streams such as returned by
3142
- :func: `open `.
3152
+ Aliases to other concrete types
3153
+ """""""""""""""""""""""""""""""
3143
3154
3144
3155
.. deprecated-removed :: 3.8 3.13
3145
3156
The ``typing.io `` namespace is deprecated and will be removed.
@@ -3186,11 +3197,11 @@ Other concrete types
3186
3197
currently planned, but users are encouraged to use
3187
3198
:class: `str ` instead of ``Text ``.
3188
3199
3189
- Abstract Base Classes
3190
- ---------------------
3200
+ .. _ abstract-base-classes :
3201
+ .. _ corresponding-to-collections-in-collections-abc :
3191
3202
3192
- Corresponding to collections in :mod: `collections.abc `
3193
- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3203
+ Aliases to container ABCs in :mod: `collections.abc `
3204
+ """""""""""""""""""""""""""""""""""""""""""""""""""
3194
3205
3195
3206
.. class :: AbstractSet(Collection[T_co])
3196
3207
@@ -3305,86 +3316,10 @@ Corresponding to collections in :mod:`collections.abc`
3305
3316
:class: `collections.abc.ValuesView ` now supports subscripting (``[] ``).
3306
3317
See :pep: `585 ` and :ref: `types-genericalias `.
3307
3318
3308
- Corresponding to other types in :mod: `collections.abc `
3309
- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3310
-
3311
- .. class :: Iterable(Generic[T_co])
3312
-
3313
- Deprecated alias to :class: `collections.abc.Iterable `.
3314
-
3315
- .. deprecated :: 3.9
3316
- :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3317
- See :pep: `585 ` and :ref: `types-genericalias `.
3318
-
3319
- .. class :: Iterator(Iterable[T_co])
3320
-
3321
- Deprecated alias to :class: `collections.abc.Iterator `.
3322
-
3323
- .. deprecated :: 3.9
3324
- :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3325
- See :pep: `585 ` and :ref: `types-genericalias `.
3326
-
3327
- .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3328
-
3329
- Deprecated alias to :class: `collections.abc.Generator `.
3330
-
3331
- A generator can be annotated by the generic type
3332
- ``Generator[YieldType, SendType, ReturnType] ``. For example::
3333
-
3334
- def echo_round() -> Generator[int, float, str]:
3335
- sent = yield 0
3336
- while sent >= 0:
3337
- sent = yield round(sent)
3338
- return 'Done'
3339
-
3340
- Note that unlike many other generics in the typing module, the ``SendType ``
3341
- of :class: `Generator ` behaves contravariantly, not covariantly or
3342
- invariantly.
3343
-
3344
- If your generator will only yield values, set the ``SendType `` and
3345
- ``ReturnType `` to ``None ``::
3346
-
3347
- def infinite_stream(start: int) -> Generator[int, None, None]:
3348
- while True:
3349
- yield start
3350
- start += 1
3351
-
3352
- Alternatively, annotate your generator as having a return type of
3353
- either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3354
-
3355
- def infinite_stream(start: int) -> Iterator[int]:
3356
- while True:
3357
- yield start
3358
- start += 1
3359
-
3360
- .. deprecated :: 3.9
3361
- :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3362
- See :pep: `585 ` and :ref: `types-genericalias `.
3363
-
3364
- .. class :: Hashable
3365
-
3366
- Deprecated alias to :class: `collections.abc.Hashable `.
3367
-
3368
- .. deprecated :: 3.12
3369
- Use :class: `collections.abc.Hashable ` directly instead.
3370
-
3371
- .. class :: Reversible(Iterable[T_co])
3372
-
3373
- Deprecated alias to :class: `collections.abc.Reversible `.
3319
+ .. _asynchronous-programming :
3374
3320
3375
- .. deprecated :: 3.9
3376
- :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3377
- See :pep: `585 ` and :ref: `types-genericalias `.
3378
-
3379
- .. class :: Sized
3380
-
3381
- Deprecated alias to :class: `collections.abc.Sized `.
3382
-
3383
- .. deprecated :: 3.12
3384
- Use :class: `collections.abc.Sized ` directly instead.
3385
-
3386
- Asynchronous programming
3387
- """"""""""""""""""""""""
3321
+ Aliases to asynchronous ABCs in :mod: `collections.abc `
3322
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""
3388
3323
3389
3324
.. class :: Coroutine(Awaitable[ReturnType], Generic[YieldType, SendType, ReturnType])
3390
3325
@@ -3475,9 +3410,90 @@ Asynchronous programming
3475
3410
:class: `collections.abc.Awaitable ` now supports subscripting (``[] ``).
3476
3411
See :pep: `585 ` and :ref: `types-genericalias `.
3477
3412
3413
+ .. _corresponding-to-other-types-in-collections-abc :
3414
+
3415
+ Aliases to other ABCs in :mod: `collections.abc `
3416
+ """""""""""""""""""""""""""""""""""""""""""""""
3417
+
3418
+ .. class :: Iterable(Generic[T_co])
3419
+
3420
+ Deprecated alias to :class: `collections.abc.Iterable `.
3421
+
3422
+ .. deprecated :: 3.9
3423
+ :class: `collections.abc.Iterable ` now supports subscripting (``[] ``).
3424
+ See :pep: `585 ` and :ref: `types-genericalias `.
3425
+
3426
+ .. class :: Iterator(Iterable[T_co])
3427
+
3428
+ Deprecated alias to :class: `collections.abc.Iterator `.
3429
+
3430
+ .. deprecated :: 3.9
3431
+ :class: `collections.abc.Iterator ` now supports subscripting (``[] ``).
3432
+ See :pep: `585 ` and :ref: `types-genericalias `.
3433
+
3434
+ .. class :: Generator(Iterator[YieldType], Generic[YieldType, SendType, ReturnType])
3435
+
3436
+ Deprecated alias to :class: `collections.abc.Generator `.
3437
+
3438
+ A generator can be annotated by the generic type
3439
+ ``Generator[YieldType, SendType, ReturnType] ``. For example::
3440
+
3441
+ def echo_round() -> Generator[int, float, str]:
3442
+ sent = yield 0
3443
+ while sent >= 0:
3444
+ sent = yield round(sent)
3445
+ return 'Done'
3446
+
3447
+ Note that unlike many other generics in the typing module, the ``SendType ``
3448
+ of :class: `Generator ` behaves contravariantly, not covariantly or
3449
+ invariantly.
3450
+
3451
+ If your generator will only yield values, set the ``SendType `` and
3452
+ ``ReturnType `` to ``None ``::
3453
+
3454
+ def infinite_stream(start: int) -> Generator[int, None, None]:
3455
+ while True:
3456
+ yield start
3457
+ start += 1
3458
+
3459
+ Alternatively, annotate your generator as having a return type of
3460
+ either ``Iterable[YieldType] `` or ``Iterator[YieldType] ``::
3461
+
3462
+ def infinite_stream(start: int) -> Iterator[int]:
3463
+ while True:
3464
+ yield start
3465
+ start += 1
3466
+
3467
+ .. deprecated :: 3.9
3468
+ :class: `collections.abc.Generator ` now supports subscripting (``[] ``).
3469
+ See :pep: `585 ` and :ref: `types-genericalias `.
3470
+
3471
+ .. class :: Hashable
3472
+
3473
+ Deprecated alias to :class: `collections.abc.Hashable `.
3474
+
3475
+ .. deprecated :: 3.12
3476
+ Use :class: `collections.abc.Hashable ` directly instead.
3477
+
3478
+ .. class :: Reversible(Iterable[T_co])
3479
+
3480
+ Deprecated alias to :class: `collections.abc.Reversible `.
3481
+
3482
+ .. deprecated :: 3.9
3483
+ :class: `collections.abc.Reversible ` now supports subscripting (``[] ``).
3484
+ See :pep: `585 ` and :ref: `types-genericalias `.
3485
+
3486
+ .. class :: Sized
3487
+
3488
+ Deprecated alias to :class: `collections.abc.Sized `.
3489
+
3490
+ .. deprecated :: 3.12
3491
+ Use :class: `collections.abc.Sized ` directly instead.
3492
+
3493
+ .. _context-manager-types :
3478
3494
3479
- Context manager types
3480
- """""""""""""""""""""
3495
+ Aliases to :mod: ` contextlib ` ABCs
3496
+ """""""""""""""""""""""""""""""""
3481
3497
3482
3498
.. class :: ContextManager(Generic[T_co])
3483
3499
0 commit comments