summaryrefslogtreecommitdiffstats
path: root/Doc/library/stdtypes.rst
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-06-07 17:26:23 (GMT)
committerGitHub <noreply@github.com>2023-06-07 17:26:23 (GMT)
commitfbdee000de47ae96fbf53ce8908e8efbb23cfba4 (patch)
tree2cfceaf576236eb4a4db4b862096fde7be732a6b /Doc/library/stdtypes.rst
parentc85be33acc29f36e07b6220b17f994de7e71801b (diff)
downloadcpython-fbdee000de47ae96fbf53ce8908e8efbb23cfba4.zip
cpython-fbdee000de47ae96fbf53ce8908e8efbb23cfba4.tar.gz
cpython-fbdee000de47ae96fbf53ce8908e8efbb23cfba4.tar.bz2
gh-90015: Document that PEP-604 unions do not support forward references (#105366)
Diffstat (limited to 'Doc/library/stdtypes.rst')
-rw-r--r--Doc/library/stdtypes.rst8
1 files changed, 8 insertions, 0 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index fdef531..0caa725 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -5162,6 +5162,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: