Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn

Union type; ``Union[X, Y]`` is equivalent to ``X | Y`` and means either X or Y.

To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | str``. Details:
To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | str``. Using that shorthand is recommended. Details:

* The arguments must be types and there must be at least one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguments are only present when using the Union[X, Y] syntax. Prepend a clarification on this "When using Union[] syntax, the arguments ..."

Add something that covers what may be |ed together. "Only types may be used with the | operator for this purpose" or similar perhaps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text is technically in the "module contents" section. There is more on X|Y in the docs for the types module. Maybe we could link there (on the word "shorthand") like was done in the first version of this PR. If the description of X|Y there is not clear enough it should be updated there IMO.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crosslinking shorthand does make sense. Otherwise I think the text here is clear enough as is.


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
State that ``|`` is preferred for readability over ``Union`` in the :mod:`typing` docs.