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