23
23
24
24
--------------
25
25
26
- This module provides runtime support for type hints. The most fundamental
27
- support consists of the types :data: `Any `, :data: `Union `, :data: `Callable `,
28
- :class: `TypeVar `, and :class: `Generic `. For a specification, please see
29
- :pep: `484 `. For a simplified introduction to type hints, see :pep: `483 `.
26
+ This module provides runtime support for type hints. For the original
27
+ specification of the typing system, see :pep: `484 `. For a simplified
28
+ introduction to type hints, see :pep: `483 `.
30
29
31
30
32
31
The function below takes and returns a string and is annotated as follows::
@@ -47,16 +46,18 @@ For a summary of deprecated features and a deprecation timeline, please see
47
46
48
47
.. seealso ::
49
48
50
- For a quick overview of type hints, refer to
51
- ` this cheat sheet < https:// mypy.readthedocs.io/en/stable/cheat_sheet_py3.html >`_.
49
+ ` "Typing cheat sheet" < https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html >`_
50
+ A quick overview of type hints (hosted at the mypy docs)
52
51
53
- The "Type System Reference" section of https://mypy.readthedocs.io/ -- since
54
- the Python typing system is standardised via PEPs, this reference should
55
- broadly apply to most Python type checkers, although some parts may still be
56
- specific to mypy.
52
+ "Type System Reference" section of ` the mypy docs < https://mypy.readthedocs.io/en/stable/index.html >`_
53
+ The Python typing system is standardised via PEPs, so this reference
54
+ should broadly apply to most Python type checkers. (Some parts may still
55
+ be specific to mypy.)
57
56
58
- The documentation at https://typing.readthedocs.io/ serves as useful reference
59
- for type system features, useful typing related tools and typing best practices.
57
+ `"Static Typing with Python" <https://typing.readthedocs.io/en/latest/ >`_
58
+ Type-checker-agnostic documentation written by the community detailing
59
+ type system features, useful typing related tools and typing best
60
+ practices.
60
61
61
62
.. _relevant-peps :
62
63
@@ -654,33 +655,16 @@ can define new custom protocols to fully enjoy structural subtyping
654
655
Module contents
655
656
===============
656
657
657
- The module defines the following classes, functions and decorators.
658
-
659
- .. note ::
660
-
661
- This module defines several deprecated aliases to pre-existing
662
- standard library classes. These were originally included in the typing
663
- module in order to support parameterizing these generic classes using ``[] ``.
664
- However, the aliases became redundant in Python 3.9 when the
665
- corresponding pre-existing classes were enhanced to support ``[] ``.
666
-
667
- The redundant types are deprecated as of Python 3.9 but no
668
- deprecation warnings are issued by the interpreter.
669
- It is expected that type checkers will flag the deprecated types
670
- when the checked program targets Python 3.9 or newer.
671
-
672
- The deprecated types will be removed from the :mod: `typing ` module
673
- no sooner than the first Python version released 5 years after the release of Python 3.9.0.
674
- See details in :pep: `585 `—*Type Hinting Generics In Standard Collections *.
675
-
658
+ The ``typing `` module defines the following classes, functions and decorators.
676
659
677
660
Special typing primitives
678
661
-------------------------
679
662
680
663
Special types
681
664
"""""""""""""
682
665
683
- These can be used as types in annotations and do not support ``[] ``.
666
+ These can be used as types in annotations. They do not support subscription
667
+ using ``[] ``.
684
668
685
669
.. data :: Any
686
670
@@ -890,7 +874,8 @@ These can be used as types in annotations and do not support ``[]``.
890
874
Special forms
891
875
"""""""""""""
892
876
893
- These can be used as types in annotations using ``[] ``, each having a unique syntax.
877
+ These can be used as types in annotations. They all support subscription using
878
+ ``[] ``, but each has a unique syntax.
894
879
895
880
.. data :: Tuple
896
881
@@ -1471,7 +1456,8 @@ These can be used as types in annotations using ``[]``, each having a unique syn
1471
1456
Building generic types and type aliases
1472
1457
"""""""""""""""""""""""""""""""""""""""
1473
1458
1474
- The following objects are not used directly in annotations. Instead, they are building blocks
1459
+ The following classes should not be used directly as annotations.
1460
+ Their intended purpose is to be building blocks
1475
1461
for creating generic types and type aliases.
1476
1462
1477
1463
These objects can be created through special syntax
@@ -1962,7 +1948,9 @@ without the dedicated syntax, as documented below.
1962
1948
Other special directives
1963
1949
""""""""""""""""""""""""
1964
1950
1965
- These are not used in annotations. They are building blocks for declaring types.
1951
+ These functions and classes should not be used directly as annotations.
1952
+ Their intended purpose is to be building blocks for creating and declaring
1953
+ types.
1966
1954
1967
1955
.. class :: NamedTuple
1968
1956
@@ -2386,7 +2374,8 @@ These are not used in annotations. They are building blocks for declaring types.
2386
2374
Protocols
2387
2375
---------
2388
2376
2389
- These protocols are decorated with :func: `runtime_checkable `.
2377
+ The following protocols are provided by the typing module. All are decorated
2378
+ with :func: `@runtime_checkable <runtime_checkable> `.
2390
2379
2391
2380
.. class :: SupportsAbs
2392
2381
@@ -3024,6 +3013,21 @@ Constant
3024
3013
Deprecated aliases
3025
3014
------------------
3026
3015
3016
+ This module defines several deprecated aliases to pre-existing
3017
+ standard library classes. These were originally included in the typing
3018
+ module in order to support parameterizing these generic classes using ``[] ``.
3019
+ However, the aliases became redundant in Python 3.9 when the
3020
+ corresponding pre-existing classes were enhanced to support ``[] ``.
3021
+
3022
+ The redundant types are deprecated as of Python 3.9 but no
3023
+ deprecation warnings are issued by the interpreter.
3024
+ It is expected that type checkers will flag the deprecated types
3025
+ when the checked program targets Python 3.9 or newer.
3026
+
3027
+ The deprecated types will be removed from the :mod: `typing ` module
3028
+ no sooner than the first Python version released 5 years after the release of Python 3.9.0.
3029
+ See details in :pep: `585 `—*Type Hinting Generics In Standard Collections *.
3030
+
3027
3031
.. _corresponding-to-built-in-types :
3028
3032
3029
3033
Aliases to built-in types
0 commit comments