[Python-ideas] Variadic patterns

2022-09-13 Thread Matt del Valle
I couldn't find any information on whether this was considered and rejected during the pattern matching PEP, so apologies if this is already settled. I've just encountered this use-case repeatedly so I figured it was time to make a thread on this. Basically, I'd like to be able to designate a pat

[Python-ideas] Re: Variadic patterns

2022-09-13 Thread Valentin Berlier
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] Re: Variadic patterns

2022-09-13 Thread Matt del Valle
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