@@ -53,7 +53,7 @@ provides backports of these new features to older versions of Python.
5353 should broadly apply to most Python type checkers. (Some parts may still
5454 be specific to mypy.)
5555
56- `"Static Typing with Python" <https://typing.readthedocs.io /en/latest/ >`_
56+ `"Static Typing with Python" <https://typing.python.org /en/latest/ >`_
5757 Type-checker-agnostic documentation written by the community detailing
5858 type system features, useful typing related tools and typing best
5959 practices.
@@ -64,7 +64,7 @@ Specification for the Python Type System
6464========================================
6565
6666The canonical, up-to-date specification of the Python type system can be
67- found at `"Specification for the Python type system" <https://typing.readthedocs.io /en/latest/spec/index.html >`_.
67+ found at `"Specification for the Python type system" <https://typing.python.org /en/latest/spec/index.html >`_.
6868
6969.. _type-aliases :
7070
@@ -1086,7 +1086,7 @@ Special forms
10861086These can be used as types in annotations. They all support subscription using
10871087``[] ``, but each has a unique syntax.
10881088
1089- .. data :: Union
1089+ .. class :: Union
10901090
10911091 Union type; ``Union[X, Y] `` is equivalent to ``X | Y `` and means either X or Y.
10921092
@@ -1121,6 +1121,14 @@ These can be used as types in annotations. They all support subscription using
11211121 Unions can now be written as ``X | Y ``. See
11221122 :ref: `union type expressions<types-union> `.
11231123
1124+ .. versionchanged :: 3.14
1125+ :class: `types.UnionType ` is now an alias for :class: `Union `, and both
1126+ ``Union[int, str] `` and ``int | str `` create instances of the same class.
1127+ To check whether an object is a ``Union `` at runtime, use
1128+ ``isinstance(obj, Union) ``. For compatibility with earlier versions of
1129+ Python, use
1130+ ``get_origin(obj) is typing.Union or get_origin(obj) is types.UnionType ``.
1131+
11241132.. data :: Optional
11251133
11261134 ``Optional[X] `` is equivalent to ``X | None `` (or ``Union[X, None] ``).
@@ -2292,6 +2300,20 @@ without the dedicated syntax, as documented below.
22922300
22932301 .. versionadded :: 3.14
22942302
2303+ .. rubric :: Unpacking
2304+
2305+ Type aliases support star unpacking using the ``*Alias `` syntax.
2306+ This is equivalent to using ``Unpack[Alias] `` directly:
2307+
2308+ .. doctest ::
2309+
2310+ >>> type Alias = tuple[int , str ]
2311+ >>> type Unpacked = tuple[bool , * Alias]
2312+ >>> Unpacked.__value__
2313+ tuple[bool, typing.Unpack[Alias]]
2314+
2315+ .. versionadded :: next
2316+
22952317
22962318Other special directives
22972319""""""""""""""""""""""""
@@ -2551,15 +2573,20 @@ types.
25512573
25522574 This functional syntax allows defining keys which are not valid
25532575 :ref: `identifiers <identifiers >`, for example because they are
2554- keywords or contain hyphens::
2576+ keywords or contain hyphens, or when key names must not be
2577+ :ref: `mangled <private-name-mangling >` like regular private names::
25552578
25562579 # raises SyntaxError
25572580 class Point2D(TypedDict):
25582581 in: int # 'in' is a keyword
25592582 x-y: int # name with hyphens
25602583
2584+ class Definition(TypedDict):
2585+ __schema: str # mangled to `_Definition__schema`
2586+
25612587 # OK, functional syntax
25622588 Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})
2589+ Definition = TypedDict('Definition', {'__schema': str}) # not mangled
25632590
25642591 By default, all keys must be present in a ``TypedDict ``. It is possible to
25652592 mark individual keys as non-required using :data: `NotRequired `::
@@ -2885,7 +2912,7 @@ Functions and decorators
28852912
28862913 .. seealso ::
28872914 `Unreachable Code and Exhaustiveness Checking
2888- <https://typing.readthedocs.io /en/latest/guides/unreachable.html> `__ has more
2915+ <https://typing.python.org /en/latest/guides/unreachable.html> `__ has more
28892916 information about exhaustiveness checking with static typing.
28902917
28912918 .. versionadded :: 3.11
0 commit comments