[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-21 Thread Guido van Rossum
Thanks very much for the survey (which actually surprised me somewhat). Regarding the suggested update for the PEP, I'll make a PR to change that -- I agree it's worth saying it. On Sat, Nov 21, 2020 at 5:00 PM David Foster wrote: > On 11/19/20 10:08 PM, David Foster wrote: > > I've completed m

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-21 Thread David Foster
On 11/19/20 10:08 PM, David Foster wrote: I've completed my survey of how other languages use pattern matching to match Mapping-like and dict-like types, especially focusing on whether they ignore (𝔸) or disallow (𝔹) extra keys by default. [...] To close the loop on this thread: * Based on (1

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-19 Thread David Foster
On 11/15/20 12:11 AM, Steven D'Aprano wrote: It would be good if the PEP gave a survey of the practical experience of other languages with pattern matching: - are there languages which require an exact match, with no left over    keys? what issues, if any, do users have with that choice? - whic

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-17 Thread Valentin Berlier
I'm in favor of keeping the PEP as it currently is. Mappings are naturally structural subtypes of one another, therefore mapping patterns should be consistent with class patterns. car = Car(...) match car: case Vehicle(): pass case Car(): # will never match

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-17 Thread Valentin Berlier
I'm in favor of keeping the PEP as it currently is. Mappings are naturally structural subtypes of one another, therefore mapping patterns should be consistent with class patterns. car = Car(...) match car: case Vehicle(): pass case Car(): # will never match

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-17 Thread Guido van Rossum
Go for it. This is a pretty minor issue but we want to get it right. Data is helpful. On Tue, Nov 17, 2020 at 06:58 David Foster wrote: > On 11/15/20 12:11 AM, Steven D'Aprano wrote: > > It would be good if the PEP gave a survey of the practical experience of > > other languages with pattern mat

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-17 Thread David Foster
On 11/15/20 12:11 AM, Steven D'Aprano wrote: It would be good if the PEP gave a survey of the practical experience of other languages with pattern matching: - are there languages which require an exact match, with no left over keys? what issues, if any, do users have with that choice? - whic

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-15 Thread 2QdxY4RzWzUUiLuE
On 2020-11-15 at 19:11:15 +1100, Steven D'Aprano wrote: > On Sat, Nov 14, 2020 at 10:17:34PM -0800, Guido van Rossum wrote: > > > It’s a usability issue; mappings are used quite differently than sequences. > > Compare to class patterns rather than sequence patterns. > > I'm keeping an open mind

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-15 Thread Steven D'Aprano
On Sat, Nov 14, 2020 at 10:17:34PM -0800, Guido van Rossum wrote: > It’s a usability issue; mappings are used quite differently than sequences. > Compare to class patterns rather than sequence patterns. I'm keeping an open mind on this question, but I think David is right to raise it. I think t

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-14 Thread Guido van Rossum
I’m surprised PEP 635 doesn’t explain this at least as well as 622? Also in your example 1, the narrower pattern (three keys) should precede the more general pattern (two). Again, same as class patterns. Or except clauses (catch RuntimeError *before* Exception). On Sat, Nov 14, 2020 at 22:49 Davi

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-14 Thread David Foster
On 11/14/20 10:17 PM, Guido van Rossum wrote: It’s a usability issue; mappings are used quite differently than sequences. Compare to class patterns rather than sequence patterns. I just found the following explanation from the superceded PEP 622 as to why extra keys are ignored: > Extra keys

[Python-ideas] Re: PEP 634-636: Mapping patterns and extra keys

2020-11-14 Thread Guido van Rossum
It’s a usability issue; mappings are used quite differently than sequences. Compare to class patterns rather than sequence patterns. On Sat, Nov 14, 2020 at 22:04 David Foster wrote: > From PEP 636 (Structural Pattern Matching): > > Mapping patterns: {"bandwidth": b, "latency": l} captures the