summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-07-15 01:00:35 (GMT)
committerGitHub <noreply@github.com>2021-07-15 01:00:35 (GMT)
commit016af14d93cfba43e7a95721a97fa954c534af8e (patch)
tree44fa512a709f45edb5086ca578bf90ad2e1d3cc4 /Doc/reference
parentff7af2203c1f03d9300e93e3e06a47fb78cc2bef (diff)
downloadcpython-016af14d93cfba43e7a95721a97fa954c534af8e.zip
cpython-016af14d93cfba43e7a95721a97fa954c534af8e.tar.gz
cpython-016af14d93cfba43e7a95721a97fa954c534af8e.tar.bz2
[3.10] bpo-44589: raise a SyntaxError when mapping patterns have duplicate literal keys (GH-27131) (GH-27157)
(cherry picked from commit 2693132292b2acf381ac6fa729bf3acf41d9d72b) Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com> Automerge-Triggered-By: GH:brandtbucher
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/compound_stmts.rst9
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 0274095..a743898 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