8000 gh-112194: Convert more examples to doctests in `typing.py` by sobolevn · Pull Request #112195 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112194: Convert more examples to doctests in typing.py #112195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Address review
  • Loading branch information
sobolevn committed Nov 17, 2023
commit 5e1d5d35d8701641d4ca8495d9b287a55fc89227
8 changes: 4 additions & 4 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,19 +678,19 @@ def Union(self, parameters):
type(None).
- Unions of unions are flattened, e.g.::

>>> assert Union[Union[int, str], float] == Union[int, str, float]
assert Union[Union[int, str], float] == Union[int, str, float]

- Unions of a single argument vanish, e.g.::

>>> assert Union[int] == int # The constructor actually returns int
assert Union[int] == int # The constructor actually returns int

- Redundant arguments are skipped, e.g.::

>>> assert Union[int, str, int] == Union[int, str]
assert Union[int, str, int] == Union[int, str]

- When comparing unions, the argument order is ignored, e.g.::

>>> assert Union[int, str] == Union[str, int]
assert Union[int, str] == Union[str, int]

- You cannot subclass or instantiate a union.
- You can use Optional[X] as a shorthand for Union[X, None].
Expand Down
0