]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141510: Fix frozendict.items() ^ frozendict.items() (#145535)
authorVictor Stinner <vstinner@python.org>
Thu, 5 Mar 2026 13:14:04 +0000 (14:14 +0100)
committerGitHub <noreply@github.com>
Thu, 5 Mar 2026 13:14:04 +0000 (14:14 +0100)
Add non-regression tests.

Lib/test/test_dict.py
Objects/dictobject.c

index 162b0b38f8555d07ab8c96388c210f7d54199466..45448d1264a53e3fee643cbeb7db97c57c5ad425 100644 (file)
@@ -1848,11 +1848,19 @@ class FrozenDictTests(unittest.TestCase):
                          frozendict({'x': 1, 'y': 2}))
         self.assertEqual(frozendict(x=1, y=2) | frozendict(y=5),
                          frozendict({'x': 1, 'y': 5}))
+        self.assertEqual(FrozenDict(x=1, y=2) | FrozenDict(y=5),
+                         frozendict({'x': 1, 'y': 5}))
+
         fd = frozendict(x=1, y=2)
         self.assertIs(fd | frozendict(), fd)
         self.assertIs(fd | {}, fd)
         self.assertIs(frozendict() | fd, fd)
 
+        fd = FrozenDict(x=1, y=2)
+        self.assertEqual(fd | frozendict(), fd)
+        self.assertEqual(fd | {}, fd)
+        self.assertEqual(frozendict() | fd, fd)
+
     def test_update(self):
         # test "a |= b" operator
         d = frozendict(x=1)
@@ -1863,6 +1871,11 @@ class FrozenDictTests(unittest.TestCase):
         self.assertEqual(d, frozendict({'x': 1, 'y': 2}))
         self.assertEqual(copy, frozendict({'x': 1}))
 
+    def test_items_xor(self):
+        # test "a ^ b" operator on items views
+        res = frozendict(a=1, b=2).items() ^ frozendict(b=2, c=3).items()
+        self.assertEqual(res, {('a', 1), ('c', 3)})
+
     def test_repr(self):
         d = frozendict()
         self.assertEqual(repr(d), "frozendict()")
index 14019e4f1d926f30edf68a03401501aab4226aa5..d86ab2634a9b136c23fb78014272120cdaf9297e 100644 (file)
@@ -6523,7 +6523,7 @@ dictitems_xor_lock_held(PyObject *d1, PyObject *d2)
     ASSERT_DICT_LOCKED(d1);
     ASSERT_DICT_LOCKED(d2);
 
-    PyObject *temp_dict = copy_lock_held(d1, PyFrozenDict_Check(d1));
+    PyObject *temp_dict = copy_lock_held(d1, 0);
     if (temp_dict == NULL) {
         return NULL;
     }