Skip to content
Prev Previous commit
Next Next commit
Do not preserve the metaclass on the def.
  • Loading branch information
ericsnowcurrently committed Jul 11, 2024
commit 753be4d9869bc4eb85c9c32e03447675ceb62cb7
6 changes: 2 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ managed_static_type_fini_def(PyTypeObject *def, PyTypeObject *type,
}

/* Preserve specific data before potentially wiping it. */
PyTypeObject *metaclass = Py_TYPE(type);
destructor dealloc = type->tp_dealloc;

/* Restore the static type to it's (mostly) original values.
Expand All @@ -216,6 +217,7 @@ managed_static_type_fini_def(PyTypeObject *def, PyTypeObject *type,
yet. Thankfully, those exceptional cases only require a small
subset of the type, all of which is static data. Thus, in the
meantime, we preserve those parts. */
Py_SET_TYPE(type, metaclass);
type->tp_dealloc = dealloc;
}

Expand Down Expand Up @@ -8565,10 +8567,6 @@ init_static_type(PyInterpreterState *interp, PyTypeObject *self,
managed_static_type_state_clear(interp, self, isbuiltin, initial);
}

if (initial) {
Py_SET_TYPE(def, Py_TYPE(self));
}

return res;
}

Expand Down