Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Typing docs: improve the guidance on annotating tuples #106021

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
Jun 23, 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
backticks
  • Loading branch information
AlexWaygood authored Jun 23, 2023
commit 8c792500f5c4a1ed1b1c1c67e1f633700e29101c
6 changes: 3 additions & 3 deletions 6 Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ code for tuples to have elements which are not all of the same type. For this
reason, tuples are special-cased in Python's typing system. :class:`tuple`
accepts *any number* of type arguments::

# OK: x is assigned to a tuple of length 1 where the sole element is an int
# OK: ``x`` is assigned to a tuple of length 1 where the sole element is an int
x: tuple[int] = (5,)

# OK: y is assigned to a tuple of length 2;
# OK: ``y`` is assigned to a tuple of length 2;
# element 1 is an int, element 2 is a str
y: tuple[int, str] = (5, "foo")

Expand All @@ -400,7 +400,7 @@ of the same type ``T``, use ``tuple[T, ...]``. To denote an empty tuple, use
# This reassignment is an error: all elements in ``x`` must be ints
x = ("foo", "bar")

# y can only ever be assigned to an empty tuple
# ``y`` can only ever be assigned to an empty tuple
y: tuple[()] = ()

z: tuple = ("foo", "bar")
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.