]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145089: Fix frozendict constructor (#145128)
authorVictor Stinner <vstinner@python.org>
Mon, 23 Feb 2026 07:22:29 +0000 (08:22 +0100)
committerGitHub <noreply@github.com>
Mon, 23 Feb 2026 07:22:29 +0000 (08:22 +0100)
Lib/test/test_dict.py
Objects/dictobject.c

index 14b501360d0b8e30dbf5d5cc3b5a0093cf82465d..8a4e19c95a36efb66599c14b93dd019b8359d47f 100644 (file)
@@ -1736,6 +1736,16 @@ class FrozenDictSlots(frozendict):
 
 
 class FrozenDictTests(unittest.TestCase):
+    def test_constructor(self):
+        # frozendict.__init__() has no effect
+        d = frozendict(a=1, b=2, c=3)
+        d.__init__(x=1)
+        self.assertEqual(d, frozendict(a=1, b=2, c=3))
+
+        # dict constructor cannot be used on frozendict
+        with self.assertRaises(TypeError):
+            dict.__init__(d, x=1)
+
     def test_copy(self):
         d = frozendict(x=1, y=2)
         d2 = d.copy()
index 6c802ca569d48c382ba9a456451c1cfe19757e48..35ca9933bfa8aed5f56a90839bd8e6e97ad80de2 100644 (file)
@@ -8143,7 +8143,6 @@ PyTypeObject PyFrozenDict_Type = {
     .tp_richcompare = dict_richcompare,
     .tp_iter = dict_iter,
     .tp_methods = frozendict_methods,
-    .tp_init = dict_init,
     .tp_alloc = _PyType_AllocNoTrack,
     .tp_new = frozendict_new,
     .tp_free = PyObject_GC_Del,