diff --git a/pep-0622.rst b/pep-0622.rst index 40d544b11..1f96af673 100644 --- a/pep-0622.rst +++ b/pep-0622.rst @@ -1425,6 +1425,38 @@ legitimate use for ``_`` as an important global variable, esp. in i18n) and the only reason for this prohibition was to prevent some user confusion. But it's not the hill to die on. +Use some other token as wildcard +-------------------------------- + +It has been proposed to use ``...`` (i.e., the ellipsis token) or +``*`` (star) as a wildcard. However, both these look as if an +arbitrary number of items is omitted:: + + case [a, ..., z]: ... + case [a, *, z]: ... + +Both look like the would match a sequence of at two or more items, +capturing the first and last values. + +In addition, if ``*`` were to be used as the wildcard character, we +would have to come up with some other way to capture the rest of a +sequence, currently spelled like this:: + + case [first, second, *rest]: ... + +Using an ellipsis would also be more confusing in documentation and +examples, where ``...`` is routinely used to indicate something +obvious or irrelevant. (Yes, this would also be an argument against +the other uses of ``...`` in Python, but that water is already under +the bridge.) + +Another proposal was to use ``?``. This could be acceptable, although +it would require modifying the tokenizer. But ``_`` is already used +as a throwaway target in other contexts, and this use is pretty +similar. This example is from ``difflib.py`` in the stdlib:: + + for tag, _, _, j1, j2 in group: ... + .. _deferred ideas: