mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
[3.10] bpo-44589: raise a SyntaxError when mapping patterns have duplicate literal keys (GH-27131) (GH-27157)
(cherry picked from commit 2693132292
)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
Automerge-Triggered-By: GH:brandtbucher
This commit is contained in:
parent
ff7af2203c
commit
016af14d93
4 changed files with 82 additions and 19 deletions
|
@ -2901,6 +2901,40 @@ class TestSyntaxErrors(unittest.TestCase):
|
|||
pass
|
||||
""")
|
||||
|
||||
def test_mapping_pattern_duplicate_key(self):
|
||||
self.assert_syntax_error("""
|
||||
match ...:
|
||||
case {"a": _, "a": _}:
|
||||
pass
|
||||
""")
|
||||
|
||||
def test_mapping_pattern_duplicate_key_edge_case0(self):
|
||||
self.assert_syntax_error("""
|
||||
match ...:
|
||||
case {0: _, False: _}:
|
||||
pass
|
||||
""")
|
||||
|
||||
def test_mapping_pattern_duplicate_key_edge_case1(self):
|
||||
self.assert_syntax_error("""
|
||||
match ...:
|
||||
case {0: _, 0.0: _}:
|
||||
pass
|
||||
""")
|
||||
|
||||
def test_mapping_pattern_duplicate_key_edge_case2(self):
|
||||
self.assert_syntax_error("""
|
||||
match ...:
|
||||
case {0: _, -0: _}:
|
||||
pass
|
||||
""")
|
||||
|
||||
def test_mapping_pattern_duplicate_key_edge_case3(self):
|
||||
self.assert_syntax_error("""
|
||||
match ...:
|
||||
case {0: _, 0j: _}:
|
||||
pass
|
||||
""")
|
||||
|
||||
class TestTypeErrors(unittest.TestCase):
|
||||
|
||||
|
@ -3008,17 +3042,6 @@ class TestTypeErrors(unittest.TestCase):
|
|||
|
||||
class TestValueErrors(unittest.TestCase):
|
||||
|
||||
def test_mapping_pattern_checks_duplicate_key_0(self):
|
||||
x = {"a": 0, "b": 1}
|
||||
w = y = z = None
|
||||
with self.assertRaises(ValueError):
|
||||
match x:
|
||||
case {"a": y, "a": z}:
|
||||
w = 0
|
||||
self.assertIs(w, None)
|
||||
self.assertIs(y, None)
|
||||
self.assertIs(z, None)
|
||||
|
||||
def test_mapping_pattern_checks_duplicate_key_1(self):
|
||||
class Keys:
|
||||
KEY = "a"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue