On Wed, 8 Jul 2020 at 14:30, Paul Svensson <[email protected]> wrote:

> On Wed, 8 Jul 2020, Rhodri James wrote:
>
> > On 08/07/2020 11:05, Federico Salerno wrote:
> >> What I don't like is the use of _ as catch-all, which is different and
> not
> >> interdependent with its use as throwaway.
> >
> > Any name used as a pattern is a catch-all.  The only difference between
> "case
> > dummy:" and "case _:" is that "_" doesn't bind to the thing being
> matched, but
> > "dummy" does bind to it.
>
> Does "_" really deserve that special treatment ?
> If you don't want to bind to it, you can just use some other dummy,
> same way you don't use "case print:" if you don want to bind that.
>

The not binding is there only to allow the main way in which "_" is special
in match/case:

case [_, _]:

is legal

case [x, x]:

is illegal (under the last PEP I have seen) and you would instead use

case [x, y] if x == y:

See "Algebraic matching of repeated names":
https://www.python.org/dev/peps/pep-0622/#algebraic-matching-of-repeated-names
See "Guards" https://www.python.org/dev/peps/pep-0622/#id6
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/RKE7AIR7MKVG2TLWCZZ57SX2BBJEZ3OB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to