@@ -2089,8 +2089,8 @@ turtle
20892089types
20902090-----
20912091
2092- * :class: ` types.UnionType ` is now an alias for :class: ` typing.Union `.
2093- See :ref: ` below < whatsnew314-typing-union > ` for more details .
2092+ * Add read-only attributes :attr: ` !__name__ `, :attr: ` !__qualname__ ` and
2093+ :attr: ` !__origin__ ` for :class: ` types.UnionType ` instances .
20942094 (Contributed by Jelle Zijlstra in :gh: `105499 `.)
20952095
20962096
@@ -2099,38 +2099,22 @@ typing
20992099
21002100.. _whatsnew314-typing-union :
21012101
2102- * :class: ` types.UnionType ` and :class: ` typing.Union ` are now aliases for each other,
2103- meaning that both old-style unions (created with `` Union[ int, str] ``) and new-style
2104- unions (`` int | str ``) now create instances of the same runtime type . This unifies
2102+ * Both old-style unions (created with `` Union[int, str] ``) and new-style
2103+ unions (`` int | str ``) now create instances of the same runtime type,
2104+ :class: ` types.UnionType ` . This unifies
21052105 the behavior between the two syntaxes, but leads to some differences in behavior that
21062106 may affect users who introspect types at runtime:
21072107
21082108 - Both syntaxes for creating a union now produce the same string representation in
21092109 ``repr() ``. For example, ``repr(Union[int, str]) ``
21102110 is now ``"int | str" `` instead of ``"typing.Union[int, str]" ``.
2111- - Unions created using the old syntax are no longer cached. Previously, running
2112- ``Union[int, str] `` multiple times would return the same object
2113- (``Union[int, str] is Union[int, str] `` would be ``True ``), but now it will
2114- return two different objects. Users should use ``== `` to compare unions for equality, not
2115- ``is ``. New-style unions have never been cached this way.
2116- This change could increase memory usage for some programs that use a large number of
2117- unions created by subscripting ``typing.Union ``. However, several factors offset this cost:
2118- unions used in annotations are no longer evaluated by default in Python 3.14
2119- because of :pep: `649 `; an instance of :class: `types.UnionType ` is
2120- itself much smaller than the object returned by ``Union[] `` was on prior Python
2121- versions; and removing the cache also saves some space. It is therefore
2122- unlikely that this change will cause a significant increase in memory usage for most
2123- users.
21242111 - Previously, old-style unions were implemented using the private class
21252112 ``typing._UnionGenericAlias ``. This class is no longer needed for the implementation,
21262113 but it has been retained for backward compatibility, with removal scheduled for Python
21272114 3.17. Users should use documented introspection helpers like :func: `typing.get_origin `
21282115 and :func: `typing.get_args ` instead of relying on private implementation details.
2129- - It is now possible to use :class: `typing.Union ` itself in :func: `isinstance ` checks.
2130- For example, ``isinstance(int | str, typing.Union) `` will return ``True ``; previously
2131- this raised :exc: `TypeError `.
2132- - The ``__args__ `` attribute of :class: `typing.Union ` objects is no longer writable.
2133- - It is no longer possible to set any attributes on :class: `typing.Union ` objects.
2116+ - The ``__args__ `` attribute of :data: `typing.Union ` objects is no longer writable.
2117+ - It is no longer possible to set any attributes on the :data: `typing.Union ` objects.
21342118 This only ever worked for dunder attributes on previous versions, was never
21352119 documented to work, and was subtly broken in many cases.
21362120
@@ -2782,8 +2766,8 @@ Changes in the Python API
27822766 This temporary change affects other threads.
27832767 (Contributed by Serhiy Storchaka in :gh: `69998 `.)
27842768
2785- * :class: ` types.UnionType ` is now an alias for :class: `typing.Union `,
2786- causing changes in some behaviors.
2769+ * Subscription of :data: ` typing.Union ` now returns a :class: `types.UnionType `
2770+ instance, causing changes in some behaviors.
27872771 See :ref: `above <whatsnew314-typing-union >` for more details.
27882772 (Contributed by Jelle Zijlstra in :gh: `105499 `.)
27892773
0 commit comments