@@ -252,7 +252,7 @@ managed_static_type_state_clear(PyInterpreterState *interp, PyTypeObject *self,
252252 state -> type = NULL ;
253253 assert (state -> tp_weaklist == NULL ); // It was already cleared out.
254254
255- if (final ) {
255+ if (final && isbuiltin ) {
256256 managed_static_type_index_clear (self );
257257 }
258258
@@ -400,7 +400,9 @@ set_tp_bases(PyTypeObject *self, PyObject *bases)
400400 if (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
401401 // XXX tp_bases can probably be statically allocated for each
402402 // static builtin type.
403- assert (_Py_IsMainInterpreter (_PyInterpreterState_GET ()));
403+ PyInterpreterState * interp = _PyInterpreterState_GET ();
404+ managed_static_type_state * state = managed_static_type_state_get (interp , self );
405+ assert (!state -> isbuiltin || _Py_IsMainInterpreter (interp ));
404406 assert (self -> tp_bases == NULL );
405407 if (PyTuple_GET_SIZE (bases ) == 0 ) {
406408 assert (self -> tp_base == NULL );
@@ -473,7 +475,9 @@ set_tp_mro(PyTypeObject *self, PyObject *mro)
473475 if (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
474476 // XXX tp_mro can probably be statically allocated for each
475477 // static builtin type.
476- assert (_Py_IsMainInterpreter (_PyInterpreterState_GET ()));
478+ PyInterpreterState * interp = _PyInterpreterState_GET ();
479+ managed_static_type_state * state = managed_static_type_state_get (interp , self );
480+ assert (!state -> isbuiltin || _Py_IsMainInterpreter (interp ));
477481 assert (self -> tp_mro == NULL );
478482 /* Other checks are done via set_tp_bases. */
479483 _Py_SetImmortal (mro );
@@ -7832,7 +7836,9 @@ static int
78327836type_ready_set_bases (PyTypeObject * type )
78337837{
78347838 if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
7835- if (!_Py_IsMainInterpreter (_PyInterpreterState_GET ())) {
7839+ PyInterpreterState * interp = _PyInterpreterState_GET ();
7840+ managed_static_type_state * state = managed_static_type_state_get (interp , type );
7841+ if (state -> isbuiltin && !_Py_IsMainInterpreter (interp )) {
78367842 assert (lookup_tp_bases (type ) != NULL );
78377843 return 0 ;
78387844 }
@@ -7966,7 +7972,9 @@ type_ready_mro(PyTypeObject *type)
79667972 ASSERT_TYPE_LOCK_HELD ();
79677973
79687974 if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
7969- if (!_Py_IsMainInterpreter (_PyInterpreterState_GET ())) {
7975+ PyInterpreterState * interp = _PyInterpreterState_GET ();
7976+ managed_static_type_state * state = managed_static_type_state_get (interp , type );
7977+ if (state -> isbuiltin && !_Py_IsMainInterpreter (interp )) {
79707978 assert (lookup_tp_mro (type ) != NULL );
79717979 return 0 ;
79727980 }
0 commit comments