Skip to content

Commit 444e43e

Browse files
authored
Clarify that variadic positional parameters can be expressed with Callable (#2164)
1 parent 6308797 commit 444e43e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

docs/spec/callables.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ a function within a type expression. The syntax is
453453

454454
Parameters specified using ``Callable`` are assumed to be positional-only.
455455
The ``Callable`` form provides no way to specify keyword-only parameters,
456-
variadic parameters, or default argument values. For these use cases, see
457-
the section on `Callback protocols`_.
456+
or default argument values. For these use cases, see the section on
457+
`Callback protocols`_.
458458

459459
Meaning of ``...`` in ``Callable``
460460
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -535,6 +535,15 @@ to be :term:`consistent` with any input parameters::
535535
f3: CallbackWithInt[...] = cb # OK
536536
f4: CallbackWithStr[...] = cb # Error
537537

538+
539+
Variadic positional parameter types can be defined with with an unpacked tuple
540+
of the form ``*tuple[int, ...]`` in the parameter list. The first argument
541+
specifies the type of the variadic parameters.
542+
For example, the following defines a callable that accepts any number of integer
543+
arguments::
544+
545+
type VarCallback = Callable[[*tuple[int, ...]], None]
546+
538547
.. _`callback-protocols`:
539548

540549
Callback protocols

0 commit comments

Comments
 (0)