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 David Foster <davidf...@gmail.com> wrote: > 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 in the subject are ignored even if **rest is not present. > This is different from > > sequence pattern, where extra items will cause a match to fail. But > mappings are actually > > different from sequences: they have natural structural sub-typing > behavior, i.e., passing a > > dictionary with extra keys somewhere will likely just work. > > I suppose this makes sense when using "match" to work with a dictionary > used as a lightweight object, which I expect would be relatively common. > > The examples I originally presented assume use of "match" for parsing, > and parsing tends to default to stricter matching. :) > > -- > David Foster | Seattle, WA, USA > Contributor to TypedDict support for mypy > -- --Guido (mobile)
_______________________________________________ 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/A3H7UOTGGU3DW5BY4GQ6XL5Y63DROSHG/ Code of Conduct: http://python.org/psf/codeofconduct/