4
4
The ``tuple `` class has some special behaviors and properties that make it
5
5
different from other classes from a typing perspective. The most obvious
6
6
difference is that ``tuple `` is variadic -- it supports an arbitrary number
7
- of type arguments. Each type argument represents a single element, and those
8
- elements are immutable at runtime. These properties affect subtyping rules and
9
- other behaviors as described below.
7
+ of type arguments. At runtime, the sequence of objects contained within the
8
+ tuple is fixed at the time of construction. Elements cannot be added, removed,
9
+ reordered, or replaced after construction. These properties affect subtyping
10
+ rules and other behaviors as described below.
10
11
11
12
12
13
Tuple Type Form
@@ -79,11 +80,10 @@ the ``typing.Unpack`` special form can be used:
79
80
``tuple[int, Unpack[tuple[str, ...]], int] ``.
80
81
81
82
Unpacked tuples can also be used for ``*args `` parameters in a function
82
- signature. For example, ``def f(*args: *tuple[int, str]): ... ``. Unpacked tuples
83
+ signature: ``def f(*args: *tuple[int, str]): ... ``. Unpacked tuples
83
84
can also be used for specializing generic classes or type variables that are
84
- parameterized using a ``TypeVarTuple ``. For more details, see "``*args `` as a
85
- Type Variable Tuple" in the Generics section. [TODO: not sure how to create a
86
- link to a heading in another .rst file]
85
+ parameterized using a ``TypeVarTuple ``. For more details, see
86
+ :ref: `args_as_typevartuple `.
87
87
88
88
89
89
Type Compatibility Rules
@@ -95,7 +95,8 @@ For example, ``tuple[int, int]`` is a subtype of ``tuple[float, complex]``.
95
95
As discussed above, a homogeneous tuple of arbitrary length is equivalent
96
96
to a union of tuples of different lengths. That means ``tuple[()] ``,
97
97
``tuple[int] `` and ``tuple[int, *tuple[int, ...]] `` are all subtypes of
98
- ``tuple[int, ...] ``.
98
+ ``tuple[int, ...] ``. The converse is not true; ``tuple[int, ...]` `` is not a
99
+ subtype of ``tuple[int] ``.
99
100
100
101
The type ``tuple[Any, ...] `` is bidirectionally compatible with any tuple::
101
102
0 commit comments