On Sat, 14 Nov 2020 at 09:51, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> On 14/11/20 7:45 am, Brandt Bucher wrote:
> > with (using your own syntactic flavor):
> > ```
> > case >first, *>middle, >last:
> >      rebuilt = first, *middle, last
> > case {"key": >value, **>rest}:
> >      rebuilt = {"key": value, **rest}
> > case Point(x=>a, y=>b):
> >      rebuilt = Point(x=a, y=b)
>
> I think this is a case where syntax matters. To my eyes this
> looks far less confusing:
>
> case ?first, *?middle, ?last:
>       rebuilt = first, *middle, last
> case {"key": ?value, **?rest}:
>       rebuilt = {"key": value, **rest}
> case Point(x=?a, y=?b):
>       rebuilt = Point(x=a, y=b)

Based on the discussion in this thread, v3 of PEP 642 is going to
propose spelling these as:

    case first, *middle, last:
         rebuilt = first, *middle, last
    case {"key" as value, **rest}:
         rebuilt = {"key": value, **rest}
    case Point(x as a, y as b):
         rebuilt = Point(x=a, y=b)

I'm in agreement with the PEP 634 authors that we want to keep
sequence pattern matching consistent with iterable unpacking as far as
name binding is concerned. Mapping patterns and class patterns are
both completely new though, and I think the readability problem there
is quite similar to the one that existed with walrus patterns in PEP
622, and thus amenable to a similar solution (i.e. spell the capture
patterns for those cases with `as`, not `:` or `=`).

Cheers,
Nick.

P.S. I've started my TODO list for v3 at
https://github.com/ncoghlan/peps/issues/6

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YQN4OXCSYVPQLQYM3ECZSIHBGMEAMJZG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to