Skip to content

Commit

Permalink
[3.11] gh-90015: Document that PEP-604 unions do not support forward …
Browse files Browse the repository at this point in the history
…references (GH-105366) (#105461)

gh-90015: Document that PEP-604 unions do not support forward references (GH-105366)
(cherry picked from commit fbdee00)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
miss-islington and AlexWaygood authored Jun 7, 2023
1 parent 34f2390 commit 40d1d28
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5109,6 +5109,14 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
def square(number: int | float) -> int | float:
return number ** 2

.. note::

The ``|`` operand cannot be used at runtime to define unions where one or
more members is a forward reference. For example, ``int | "Foo"``, where
``"Foo"`` is a reference to a class not yet defined, will fail at
runtime. For unions which include forward references, present the
whole expression as a string, e.g. ``"int | Foo"``.

.. describe:: union_object == other

Union objects can be tested for equality with other union objects. Details:
Expand Down

0 comments on commit 40d1d28

Please sign in to comment.