PEP 622: Strengthen the argument for _ as wildcard (#1488)
See https://github.com/gvanrossum/patma/issues/93#issuecomment-650723402 Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
4b7f1fcd4c
commit
045450aaf4
20
pep-0622.rst
20
pep-0622.rst
|
@ -981,7 +981,6 @@ A small collection of example code is
|
|||
`available on GitHub <https://github.com/gvanrossum/patma/tree/master/examples>`_.
|
||||
|
||||
|
||||
|
||||
.. _rejected ideas:
|
||||
|
||||
Rejected Ideas
|
||||
|
@ -1384,12 +1383,29 @@ 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
|
||||
it would require modifying the tokenizer.
|
||||
|
||||
Also, ``_`` 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: ...
|
||||
|
||||
Perhaps the most convincing argument is that ``_`` is used as the
|
||||
wildcard in every other language we've looked at supporting pattern
|
||||
matching: C#, Elixir, Erlang, F#, Haskell, Mathematica, OCaml, Ruby,
|
||||
Rust, Scala, and Swift. Now, in general, we should not be concerned
|
||||
too much with what another language does, since Python is clearly
|
||||
different from all these languages. However, if there is such an
|
||||
overwhelming and strong consensus, Python should not go out of its way
|
||||
to do something completely different -- particularly given that ``_``
|
||||
works well in Python and is already in use as a throwaway target.
|
||||
|
||||
Note that ``_`` is not assigned to by patterns -- this avoids
|
||||
conflicts with the use of ``_`` as a marker for translatable strings
|
||||
and an alias for ``gettext.gettext``, as recommended by the
|
||||
``gettext`` module documentation.
|
||||
|
||||
Use some other syntax instead of ``|`` for OR patterns
|
||||
------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue