Skip to content

Commit 1786baa

Browse files
author
Daniel Sperber
committed
Clarifications
1 parent 7454eba commit 1786baa

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

peps/pep-0821.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Allowing ``Unpack[TypedDict]`` inside ``Callable`` achieves the following:
7676
with existing semantics from :pep:`692` (``Unpack`` for ``**kwargs``) and
7777
:pep:`728` (``extra_items`` and ``closed``).
7878
* Keeps the feature additive, backwards compatible, and stays mostly a
79-
typing-specification change only.
79+
typing-specification change only, see `Backwards Compatibility`_.
8080

8181
Alternatives considered
8282
-----------------------
@@ -104,11 +104,17 @@ Design trade-offs and decisions
104104
* Positional parameters: Allowing positional parameters to precede
105105
``Unpack[TD]`` retains existing ``Callable`` semantics and mirrors real
106106
Python functions where positional and keyword-only parameters coexist.
107-
* ``Concatenate``: ``Unpack[TD]`` cannot appear within ``Concatenate``
107+
108+
* ``Unpack[TD]`` cannot appear within ``Concatenate``
108109
(e.g. ``Concatenate[int, Unpack[TD], P]``), as this would enable
109110
interspersed keyword-only parameters among ``*args`` and ``**kwargs``.
110111
This increases complexity and is not proposed here.
111112

113+
* Abbreviation with ``**``: This PEP does not add a suggestion to add a ``**``
114+
shorthand (e.g. ``**TD``) for ``Unpack[TD]`` in ``Callable``. The proposal
115+
is intentionally minimal, reusing the existing ``Unpack[TD]`` form. Adding
116+
such an abbreviation would require a grammar change and is out of scope.
117+
112118
Specification
113119
=============
114120

@@ -167,18 +173,18 @@ rejected::
167173
Interaction with ``ParamSpec``, ``TypeVarTuple``, and ``Concatenate``
168174
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169175

170-
``Unpack[TD]`` cannot appear within ``Concatenate``
171-
(e.g. ``Concatenate[int, Unpack[TD], P]``); use
172-
``Callable[[int, Unpack[TD]], R]`` instead.
173-
See `Design trade-offs and decisions`_ for the rationale.
174-
175176
A ``TypeVarTuple`` may coexist with ``Unpack[TD]`` in the parameter list,
176177
because ``TypeVarTuple`` corresponds to ``*args`` and does not interfere
177178
with the ``**kwargs``-equivalent role of ``Unpack[TD]``::
178179

179-
# Tv is a TypeVarTuple, e.g. in class F[*Tv]: ...
180+
# With Tv a TypeVarTuple
180181
Callable[[Unpack[Tv], Unpack[KeywordTD]], R] # Allowed
181182

183+
``Unpack[TD]`` cannot appear within ``Concatenate``
184+
(e.g. ``Concatenate[int, Unpack[TD]]``); use
185+
``Callable[[int, Unpack[TD]], R]`` instead.
186+
See `Design trade-offs and decisions`_ for the rationale.
187+
182188
A ``ParamSpec`` may not appear alongside ``Unpack[TD]`` in the same
183189
``Callable`` parameter list, because ``ParamSpec`` covers both ``*args``
184190
and ``**kwargs``, which conflicts with ``Unpack[TD]``::

0 commit comments

Comments
 (0)