mirror of
https://github.com/python/cpython.git
synced 2025-09-23 17:03:23 +00:00
gh-90015: Document that PEP-604 unions do not support forward references (#105366)
This commit is contained in:
parent
c85be33acc
commit
fbdee000de
1 changed files with 8 additions and 0 deletions
|
@ -5162,6 +5162,14 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
|
||||||
def square(number: int | float) -> int | float:
|
def square(number: int | float) -> int | float:
|
||||||
return number ** 2
|
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
|
.. describe:: union_object == other
|
||||||
|
|
||||||
Union objects can be tested for equality with other union objects. Details:
|
Union objects can be tested for equality with other union objects. Details:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue