Skip to content

[3.11] gh-90015: Document that PEP-604 unions do not support forward references (GH-105366) #105461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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