@@ -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 `::
0 commit comments