@@ -5364,7 +5364,7 @@ Union Type
5364
5364
A union object holds the value of the ``| `` (bitwise or) operation on
5365
5365
multiple :ref: `type objects <bltin-type-objects >`. These types are intended
5366
5366
primarily for :term: `type annotations <annotation> `. The union type expression
5367
- enables cleaner type hinting syntax compared to :data : `typing.Union `.
5367
+ enables cleaner type hinting syntax compared to subscripting :class : `typing.Union `.
5368
5368
5369
5369
.. describe :: X | Y | ...
5370
5370
@@ -5400,9 +5400,10 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
5400
5400
5401
5401
int | str == str | int
5402
5402
5403
- * It is compatible with :data : `typing.Union `::
5403
+ * It creates instances of :class : `typing.Union `::
5404
5404
5405
5405
int | str == typing.Union[int, str]
5406
+ type(int | str) is typing.Union
5406
5407
5407
5408
* Optional types can be spelled as a union with ``None ``::
5408
5409
@@ -5428,16 +5429,15 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
5428
5429
TypeError: isinstance() argument 2 cannot be a parameterized generic
5429
5430
5430
5431
The user-exposed type for the union object can be accessed from
5431
- :data: `types.UnionType ` and used for :func: `isinstance ` checks. An object cannot be
5432
- instantiated from the type::
5432
+ :class: `typing.Union ` and used for :func: `isinstance ` checks::
5433
5433
5434
- >>> import types
5435
- >>> isinstance(int | str, types.UnionType )
5434
+ >>> import typing
5435
+ >>> isinstance(int | str, typing.Union )
5436
5436
True
5437
- >>> types.UnionType ()
5437
+ >>> typing.Union ()
5438
5438
Traceback (most recent call last):
5439
5439
File "<stdin>", line 1, in <module>
5440
- TypeError: cannot create 'types.UnionType ' instances
5440
+ TypeError: cannot create 'typing.Union ' instances
5441
5441
5442
5442
.. note ::
5443
5443
The :meth: `!__or__ ` method for type objects was added to support the syntax
@@ -5464,6 +5464,11 @@ instantiated from the type::
5464
5464
5465
5465
.. versionadded :: 3.10
5466
5466
5467
+ .. versionchanged :: 3.14
5468
+
5469
+ Union objects are now instances of :class: `typing.Union `. Previously, they were instances
5470
+ of :class: `types.UnionType `, which remains an alias for :class: `typing.Union `.
5471
+
5467
5472
5468
5473
.. _typesother :
5469
5474
0 commit comments