@@ -7335,18 +7335,18 @@ init_static_types(PyInterpreterState *interp, int reloading)
73357335    if  (reloading ) {
73367336        return  0 ;
73377337    }
7338-     if  (_Py_IsMainInterpreter (interp )
7339-         &&  PyType_HasFeature (& PyDateTime_DateType , Py_TPFLAGS_READY )) {
7340-         // This function was already called from PyInit__datetime() 
7341-         return  0 ;
7338+     if  (_Py_IsMainInterpreter (interp )) {
7339+         if  (PyType_HasFeature (& PyDateTime_DateType , Py_TPFLAGS_READY )) {
7340+             // This function was already called from PyInit__datetime() 
7341+             return  0 ;
7342+         }
7343+         // `&...` is not a constant expression according to a strict reading 
7344+         // of C standards. Fill tp_base at run-time rather than statically. 
7345+         // See https://bugs.python.org/issue40777 
7346+         PyDateTime_TimeZoneType .tp_base  =  & PyDateTime_TZInfoType ;
7347+         PyDateTime_DateTimeType .tp_base  =  & PyDateTime_DateType ;
73427348    }
73437349
7344-     // `&...` is not a constant expression according to a strict reading 
7345-     // of C standards. Fill tp_base at run-time rather than statically. 
7346-     // See https://bugs.python.org/issue40777 
7347-     PyDateTime_TimeZoneType .tp_base  =  & PyDateTime_TZInfoType ;
7348-     PyDateTime_DateTimeType .tp_base  =  & PyDateTime_DateType ;
7349- 
73507350    /* Bases classes must be initialized before subclasses, 
73517351     * so capi_types must have the types in the appropriate order. */ 
73527352    for  (size_t  i  =  0 ; i  <  Py_ARRAY_LENGTH (capi_types ); i ++ ) {
@@ -7569,11 +7569,13 @@ static PyModuleDef datetimemodule = {
75697569PyMODINIT_FUNC 
75707570PyInit__datetime (void )
75717571{
7572-     PyInterpreterState  * interp  =  PyInterpreterState_Get ();
7572+     PyInterpreterState  * interp  =  _PyInterpreterState_GET ();
75737573    // gh-136421: Ensure static types are fully finalized at the shutdown of 
75747574    // the main interpreter rather than subinterpreters for concurrency. 
7575-     assert (_Py_IsMainInterpreter (interp ));
7576-     init_static_types (interp , 0 );
7575+     assert (interp  !=  NULL  &&  _Py_IsMainInterpreter (interp ));
7576+     if  (init_static_types (interp , 0 ) <  0 ) {
7577+         return  NULL ;
7578+     }
75777579    return  PyModuleDef_Init (& datetimemodule );
75787580}
75797581
0 commit comments