@@ -2433,6 +2433,18 @@ These protocols are decorated with :func:`runtime_checkable`.
2433
2433
An ABC with one abstract method ``__round__ ``
2434
2434
that is covariant in its return type.
2435
2435
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
+
2436
2448
Functions and decorators
2437
2449
------------------------
2438
2450
@@ -3052,11 +3064,15 @@ Constant
3052
3064
3053
3065
.. versionadded :: 3.5.2
3054
3066
3055
- Generic concrete collections
3056
- ----------------------------
3067
+ .. _generic-concrete-collections :
3057
3068
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
+ """""""""""""""""""""""""
3060
3076
3061
3077
.. class :: Dict(dict, MutableMapping[KT, VT])
3062
3078
@@ -3118,8 +3134,10 @@ Corresponding to built-in types
3118
3134
3119
3135
.. note :: :data:`Tuple` is a special form.
3120
3136
3121
- Corresponding to types in :mod: `collections `
3122
- """"""""""""""""""""""""""""""""""""""""""""
3137
+ .. _corresponding-to-types-in-collections :
3138
+
3139
+ Aliases to types in :mod: `collections `
3140
+ """"""""""""""""""""""""""""""""""""""
3123
3141
3124
3142
.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
3125
3143
@@ -3174,17 +3192,10 @@ Corresponding to types in :mod:`collections`
3174
3192
:class: `collections.deque ` now supports subscripting (``[] ``).
3175
3193
See :pep: `585 ` and :ref: `types-genericalias `.
3176
3194
3177
- Other concrete types
3178
- """"""""""""""""""""
3195
+ .. _other-concrete-types :
3179
3196
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
+ """""""""""""""""""""""""""""""
3188
3199
3189
3200
.. class :: Pattern
3190
3201
Match
@@ -3223,11 +3234,11 @@ Other concrete types
3223
3234
currently planned, but users are encouraged to use
3224
3235
:class: `str ` instead of ``Text ``.
3225
3236
3226
- Abstract Base Classes
3227
- ---------------------
3237
+ .. _ abstract-base-classes :
3238
+ .. _ corresponding-to-collections-in-collections-abc :
3228
3239
3229
- Corresponding to collections in :mod: `collections.abc `
3230
- """"""""""""""""""""""""""""""""""""""""""""""""""""""
3240
+ Aliases to container ABCs in :mod: `collections.abc `
3241
+ """""""""""""""""""""""""""""""""""""""""""""""""""
3231
3242
3232
3243
.. class :: AbstractSet(Collection[T_co])
3233
3244
@@ -3342,86 +3353,10 @@ Corresponding to collections in :mod:`collections.abc`
3342
3353
:class: `collections.abc.ValuesView ` now supports subscripting (``[] ``).
3343
3354
See :pep: `585 ` and :ref: `types-genericalias `.
3344
3355
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 :
3411
3357
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
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""
3425
3360
3426
3361
.. class :: Coroutine(Awaitable[ReturnType], Generic[YieldType, SendType, ReturnType])
3427
3362
@@ -3512,9 +3447,90 @@ Asynchronous programming
3512
3447
:class: `collections.abc.Awaitable ` now supports subscripting (``[] ``).
3513
3448
See :pep: `585 ` and :ref: `types-genericalias `.
3514
3449
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 :
3515
3531
3516
- Context manager types
3517
- """""""""""""""""""""
3532
+ Aliases to :mod: ` contextlib ` ABCs
3533
+ """""""""""""""""""""""""""""""""
3518
3534
3519
3535
.. class :: ContextManager(Generic[T_co])
3520
3536
0 commit comments