summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJack DeVries <58614260+jdevries3133@users.noreply.github.com>2021-07-15 00:38:42 (GMT)
committerGitHub <noreply@github.com>2021-07-15 00:38:42 (GMT)
commit2693132292b2acf381ac6fa729bf3acf41d9d72b (patch)
tree11df8c03e7fdb335d61eddc75982f6c6f57ce51b /Lib
parent3b8075f9076490508567f0fb3dc689861544d1a8 (diff)
downloadcpython-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 'Lib')
-rw-r--r--Lib/test/test_patma.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/Lib/test/test_patma.py b/Lib/test/test_patma.py
index a8889ca..69a648a 100644
--- a/Lib/test/test_patma.py
+++ b/Lib/test/test_patma.py
@@ -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"