Skip to content

Commit 9b48ff9

Browse files
committed
Incorporated PR feedback from Jelle.
1 parent e373264 commit 9b48ff9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

docs/spec/generics.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ explicitly marking the code as unsafe (by using ``y: Array[*tuple[Any,
12971297
checker every time they tried to use the variable ``y``, which would
12981298
hinder them when migrating a legacy code base to use ``TypeVarTuple``.
12991299

1300+
.. _args_as_typevartuple:
13001301

13011302
``*args`` as a Type Variable Tuple
13021303
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

docs/spec/tuples.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Tuples
44
The ``tuple`` class has some special behaviors and properties that make it
55
different from other classes from a typing perspective. The most obvious
66
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.
1011

1112

1213
Tuple Type Form
@@ -79,11 +80,10 @@ the ``typing.Unpack`` special form can be used:
7980
``tuple[int, Unpack[tuple[str, ...]], int]``.
8081

8182
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
8384
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`.
8787

8888

8989
Type Compatibility Rules
@@ -95,7 +95,8 @@ For example, ``tuple[int, int]`` is a subtype of ``tuple[float, complex]``.
9595
As discussed above, a homogeneous tuple of arbitrary length is equivalent
9696
to a union of tuples of different lengths. That means ``tuple[()]``,
9797
``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]``.
99100

100101
The type ``tuple[Any, ...]`` is bidirectionally compatible with any tuple::
101102

0 commit comments

Comments
 (0)