diff options
author | Jack DeVries <58614260+jdevries3133@users.noreply.github.com> | 2021-07-15 00:38:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-15 00:38:42 (GMT) |
commit | 2693132292b2acf381ac6fa729bf3acf41d9d72b (patch) | |
tree | 11df8c03e7fdb335d61eddc75982f6c6f57ce51b /Doc/reference | |
parent | 3b8075f9076490508567f0fb3dc689861544d1a8 (diff) | |
download | cpython-2693132292b2acf381ac6fa729bf3acf41d9d72b.zip cpython-2693132292b2acf381ac6fa729bf3acf41d9d72b.tar.gz cpython-2693132292b2acf381ac6fa729bf3acf41d9d72b.tar.bz2 |
bpo-44589: raise a SyntaxError when mapping patterns have duplicate literal keys (GH-27131)
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/compound_stmts.rst | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index c405423..8afcadb 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -968,9 +968,9 @@ Syntax: At most one double star pattern may be in a mapping pattern. The double star pattern must be the last subpattern in the mapping pattern. -Duplicate key values in mapping patterns are disallowed. (If all key patterns -are literal patterns this is considered a syntax error; otherwise this is a -runtime error and will raise :exc:`ValueError`.) +Duplicate keys in mapping patterns are disallowed. Duplicate literal keys will +raise a :exc:`SyntaxError`. Two keys that otherwise have the same value will +raise a :exc:`ValueError` at runtime. The following is the logical flow for matching a mapping pattern against a subject value: @@ -982,7 +982,8 @@ subject value: mapping, the mapping pattern succeeds. #. If duplicate keys are detected in the mapping pattern, the pattern is - considered invalid and :exc:`ValueError` is raised. + considered invalid. A :exc:`SyntaxError` is raised for duplicate literal + values; or a :exc:`ValueError` for named keys of the same value. .. note:: Key-value pairs are matched using the two-argument form of the mapping subject's ``get()`` method. Matched key-value pairs must already be present |