Skip to content

Commit

Permalink
PEP 635: Explain why mapping patterns ignore extra keys (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Nov 22, 2020
1 parent 37f5b8a commit f01b03e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test program"""
9 changes: 7 additions & 2 deletions pep-0635.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,13 @@ dictionary. Particularly common are string keys.

The mapping pattern reflects the common usage of dictionary lookup: it allows
the user to extract some values from a mapping by means of constant/known
keys and have the values match given subpatterns. Moreover, the mapping
pattern does not check for the presence of additional keys. Should it be
keys and have the values match given subpatterns.
Extra keys in the subject are ignored even if ``**rest`` is not present.
This is different from sequence patterns, 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.
Should it be
necessary to impose an upper bound on the mapping and ensure that no
additional keys are present, then the usual double-star-pattern ``**rest``
can be used. The special case ``**_`` with a wildcard, however, is not
Expand Down

0 comments on commit f01b03e

Please sign in to comment.