We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c85be33 commit fbdee00Copy full SHA for fbdee00
Doc/library/stdtypes.rst
@@ -5162,6 +5162,14 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
5162
def square(number: int | float) -> int | float:
5163
return number ** 2
5164
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
5173
.. describe:: union_object == other
5174
5175
Union objects can be tested for equality with other union objects. Details:
0 commit comments