Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbdee00

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

File tree

Expand file treeCollapse file tree

1 file changed

+8
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-0
lines changed

‎Doc/library/stdtypes.rst

Copy file name to clipboardExpand all lines: Doc/library/stdtypes.rst
+8Lines changed: 8 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.