Great point Valentin. I do think it's worthwhile to allow capturing
variadic sub-patterns while destructuring.

For symmetry with variadic function arguments (*args) I would actually
suggest accumulating all the values using a tuple and bind that tuple to
the name, but I'm not precious about using a tuple vs a list. Bikesheddable
imo.

Something I forgot to mention in the original proposal is that unlike with
variadic function arguments where you can only have variadic positionals
once in the signature, in a pattern the following should be valid:

match heterogenous:
    case [
        *str() as strings,
        3,
        *bool()
    ]


Where 'heterogenous' should match an iterable starting with zero or more
strings and bind them to (subject to bikeshedding) a tuple with the name
'strings', followed by the integer 3, followed by zero or more booleans.


On Tue, Sep 13, 2022 at 3:17 PM Valentin Berlier <berlie...@gmail.com>
wrote:

> I really like this. One problem though is that it's not immediately
> obvious what happens with binding patterns and "as" clauses. In the code
> inside the case statement, should these identifiers refer to the last value
> matched, or should they accumulate all the matches in a list?
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/U6TBMZXATDAYKYUVK7B3JNHJH3XCPO76/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ULC3AJVKBWPTFTQPRII6GIPEI2FV2O4G/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to