https://github.com/python/cpython/commit/3dc8fdb3219293547890808ab52a2171867fd3af
commit: 3dc8fdb3219293547890808ab52a2171867fd3af
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-02-23T08:22:29+01:00
summary:

gh-145089: Fix frozendict constructor (#145128)

files:
M Lib/test/test_dict.py
M Objects/dictobject.c

diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 14b501360d0b8e..8a4e19c95a36ef 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -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()
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 6c802ca569d48c..35ca9933bfa8ae 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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,

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to