@@ -2071,56 +2071,9 @@ turtle
20712071 (Contributed by Marie Roald and Yngve Mardal Moe in :gh: `126350 `.)
20722072
20732073
2074- types
2075- -----
2076-
2077- * :class: `types.UnionType ` is now an alias for :class: `typing.Union `.
2078- See :ref: `below <whatsnew314-typing-union >` for more details.
2079- (Contributed by Jelle Zijlstra in :gh: `105499 `.)
2080-
2081-
20822074typing
20832075------
20842076
2085- .. _whatsnew314-typing-union :
2086-
2087- * :class: `types.UnionType ` and :class: `typing.Union ` are now aliases for each other,
2088- meaning that both old-style unions (created with ``Union[int, str] ``) and new-style
2089- unions (``int | str ``) now create instances of the same runtime type. This unifies
2090- the behavior between the two syntaxes, but leads to some differences in behavior that
2091- may affect users who introspect types at runtime:
2092-
2093- - Both syntaxes for creating a union now produce the same string representation in
2094- ``repr() ``. For example, ``repr(Union[int, str]) ``
2095- is now ``"int | str" `` instead of ``"typing.Union[int, str]" ``.
2096- - Unions created using the old syntax are no longer cached. Previously, running
2097- ``Union[int, str] `` multiple times would return the same object
2098- (``Union[int, str] is Union[int, str] `` would be ``True ``), but now it will
2099- return two different objects. Users should use ``== `` to compare unions for equality, not
2100- ``is ``. New-style unions have never been cached this way.
2101- This change could increase memory usage for some programs that use a large number of
2102- unions created by subscripting ``typing.Union ``. However, several factors offset this cost:
2103- unions used in annotations are no longer evaluated by default in Python 3.14
2104- because of :pep: `649 `; an instance of :class: `types.UnionType ` is
2105- itself much smaller than the object returned by ``Union[] `` was on prior Python
2106- versions; and removing the cache also saves some space. It is therefore
2107- unlikely that this change will cause a significant increase in memory usage for most
2108- users.
2109- - Previously, old-style unions were implemented using the private class
2110- ``typing._UnionGenericAlias ``. This class is no longer needed for the implementation,
2111- but it has been retained for backward compatibility, with removal scheduled for Python
2112- 3.17. Users should use documented introspection helpers like :func: `typing.get_origin `
2113- and :func: `typing.get_args ` instead of relying on private implementation details.
2114- - It is now possible to use :class: `typing.Union ` itself in :func: `isinstance ` checks.
2115- For example, ``isinstance(int | str, typing.Union) `` will return ``True ``; previously
2116- this raised :exc: `TypeError `.
2117- - The ``__args__ `` attribute of :class: `typing.Union ` objects is no longer writable.
2118- - It is no longer possible to set any attributes on :class: `typing.Union ` objects.
2119- This only ever worked for dunder attributes on previous versions, was never
2120- documented to work, and was subtly broken in many cases.
2121-
2122- (Contributed by Jelle Zijlstra in :gh: `105499 `.)
2123-
21242077* :class: `typing.TypeAliasType ` now supports star unpacking.
21252078
21262079
@@ -3189,11 +3142,6 @@ Changes in the Python API
31893142 This temporary change affects other threads.
31903143 (Contributed by Serhiy Storchaka in :gh: `69998 `.)
31913144
3192- * :class: `types.UnionType ` is now an alias for :class: `typing.Union `,
3193- causing changes in some behaviors.
3194- See :ref: `above <whatsnew314-typing-union >` for more details.
3195- (Contributed by Jelle Zijlstra in :gh: `105499 `.)
3196-
31973145* The runtime behavior of annotations has changed in various ways; see
31983146 :ref: `above <whatsnew314-pep649 >` for details. While most code that interacts
31993147 with annotations should continue to work, some undocumented details may behave
0 commit comments