@@ -2472,12 +2472,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
24722472 type -> tp_dictoffset = slotoffset ;
24732473 slotoffset += sizeof (PyObject * );
24742474 }
2475- else if (!type -> tp_dictoffset ) {
2476- type -> tp_dictoffset = base -> tp_dictoffset ;
2477- }
2478- if (type -> tp_dictoffset ) {
2479- et -> ht_cached_keys = _PyDict_NewKeysForClass ();
2480- }
24812475 if (add_weak ) {
24822476 assert (!base -> tp_itemsize );
24832477 type -> tp_weaklistoffset = slotoffset ;
@@ -2527,6 +2521,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
25272521 /* Put the proper slots in place */
25282522 fixup_slot_dispatchers (type );
25292523
2524+ if (type -> tp_dictoffset ) {
2525+ et -> ht_cached_keys = _PyDict_NewKeysForClass ();
2526+ }
2527+
25302528 Py_DECREF (dict );
25312529 return (PyObject * )type ;
25322530
@@ -2643,9 +2641,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
26432641 type -> tp_doc = tp_doc ;
26442642 }
26452643 }
2646- if (type -> tp_dictoffset ) {
2647- res -> ht_cached_keys = _PyDict_NewKeysForClass ();
2648- }
26492644 if (type -> tp_dealloc == NULL ) {
26502645 /* It's a heap type, so needs the heap types' dealloc.
26512646 subtype_dealloc will call the base type's tp_dealloc, if
@@ -2656,6 +2651,10 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
26562651 if (PyType_Ready (type ) < 0 )
26572652 goto fail ;
26582653
2654+ if (type -> tp_dictoffset ) {
2655+ res -> ht_cached_keys = _PyDict_NewKeysForClass ();
2656+ }
2657+
26592658 /* Set type.__module__ */
26602659 s = strrchr (spec -> name , '.' );
26612660 if (s != NULL )
0 commit comments