Skip to content

Commit fbdee00

Browse files
authored
gh-90015: Document that PEP-604 unions do not support forward references (#105366)
1 parent c85be33 commit fbdee00

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/stdtypes.rst

+8
Original file line numberDiff line numberDiff line change
@@ -5162,6 +5162,14 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
51625162
def square(number: int | float) -> int | float:
51635163
return number ** 2
51645164

5165+
.. note::
5166+
5167+
The ``|`` operand cannot be used at runtime to define unions where one or
5168+
more members is a forward reference. For example, ``int | "Foo"``, where
5169+
``"Foo"`` is a reference to a class not yet defined, will fail at
5170+
runtime. For unions which include forward references, present the
5171+
whole expression as a string, e.g. ``"int | Foo"``.
5172+
51655173
.. describe:: union_object == other
51665174

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

0 commit comments

Comments
 (0)