On Sun., 15 Nov. 2020, 5:25 pm Guido van Rossum, <gu...@python.org> wrote:

> But Point(x as a) already has a meaning in PEP 634; it’s a positional
> argument captured in x *and* in a. (Previously spelled as Point(a := x).
> The phrase ‘as a’ can be added after any pattern to *also* capture it in
> ‘a’. More typically used as e.g.‘Pattern(x, y) as p’, which captures the
> first two fields in x and y, and the whole Point in p.
>

Indeed, the proposed change I'm contemplating for class matching would
require that positional matching be opt-in rather than the default.

The default would instead become to check that the named attributes exist,
so "Pattern(x, y)" would be short for "Pattern(x=__, y=__)", and you'd have
to write "Pattern(x, y, /)" instead to request positional arg matching.

The default behaviour of class patterns would become a lot more like
mapping patterns, but working off attribute names rather than keys.

I think that will give an end result that offers the same capabilities as
PEP 634, but the proof will be in the reference implementation update.

Cheers,
Nick.





>
_______________________________________________
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/Y2PDB76J5YHO7GWXLIYXGEL4MSXUT7RT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to