Skip to content

Commit f9df030

Browse files
committed
Support dict subtypes
1 parent d0d772b commit f9df030

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/test/test_capi/test_dict.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,14 @@ def test_dict_as_frozendict_and_clear(self):
628628

629629
class DictSubtype(dict): ...
630630

631-
for wrong_input in (frozendict(), DictSubtype(), [], None):
631+
d = DictSubtype({'x': None})
632+
f = as_frozendict(d)
633+
self.assertIs(type(f), frozendict)
634+
self.assertEqual(f, frozendict({'x': None}))
635+
self.assertIs(type(d), DictSubtype)
636+
self.assertEqual(d, DictSubtype({}))
637+
638+
for wrong_input in (frozendict(), [], None):
632639
with self.subTest(wrong_input=wrong_input):
633640
with self.assertRaises(SystemError):
634641
as_frozendict(wrong_input)

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8561,7 +8561,7 @@ transfer_keys_and_values_lock_held(PyObject *res, PyObject *dict)
85618561
PyObject *
85628562
PyDict_AsFrozenDictAndClear(PyObject *dict)
85638563
{
8564-
if (dict == NULL || !PyDict_CheckExact(dict)) {
8564+
if (dict == NULL || !PyDict_Check(dict)) {
85658565
PyErr_BadInternalCall();
85668566
return NULL;
85678567
}

0 commit comments

Comments
 (0)