Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make "X | Y" union syntax more prominent in documentation - #17835

Merged
JukkaL merged 5 commits into
masterfrom
docs-union
Sep 26, 2024
Merged

Make "X | Y" union syntax more prominent in documentation#17835
JukkaL merged 5 commits into
masterfrom
docs-union

Conversation

@JukkaL

@JukkaL JukkaL commented Sep 26, 2024

Copy link
Copy Markdown
Collaborator

Soon 4 out of 5 supported Python versions will support the X | Y syntax,
so we can make it more prominent (Python 3.13 will be out soon, and 3.8
will reach end of life). Use it in most examples.

The syntax is available starting from Python 3.10, but it can be used
in annotations in earlier Python versions as well if using
from __future__ import annotations.

Soon 4 out of 5 supported Python versions will support the `X | Y` syntax,
so we can make it more prominent (Python 3.13 will be out soon, and 3.8
will reach end of life).

The syntax is available starting from Python 3.10, but it can be used
in annotations in earlier Python versions as well if using
`from __future__ import annotations`.

@JelleZijlstra JelleZijlstra left a comment

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.

Looks good, some small feedback

Comment thread docs/source/kinds_of_types.rst Outdated

Use the ``Union[T1, ..., Tn]`` type constructor to construct a union
type. For example, if an argument has type ``Union[int, str]``, both
Use the ``T1 | ... | Tn`` type constructor to construct a union

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.

Suggested change
Use the ``T1 | ... | Tn`` type constructor to construct a union
Use the ``T1 | ... | Tn`` operator to construct a union

Feels odd to call this a "type constructor"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Using "operator" here also didn't feel quite right, so I just left out the "type constructor" bit.

Comment thread docs/source/kinds_of_types.rst Outdated
Comment thread docs/source/kinds_of_types.rst Outdated
t1: int | str # equivalent to Union[int, str]

t2: int | None # equivalent to Optional[int]
The type ``... | None`` *does not* mean a function parameter with a default value.

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.

Since this confusion is related to the name Optional, it might be better to keep using Optional[T] here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

Comment thread docs/source/more_types.rst Outdated
Comment thread docs/source/command_line.rst Outdated
Comment thread docs/source/config_file.rst Outdated
Comment thread docs/source/command_line.rst Outdated
JukkaL and others added 2 commits September 26, 2024 14:50
@JukkaL
JukkaL merged commit db7b61b into master Sep 26, 2024
@JukkaL
JukkaL deleted the docs-union branch September 26, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants