@@ -7059,8 +7059,12 @@ _datetime_exec(PyObject *module)
7059
7059
}
7060
7060
}
7061
7061
7062
+ /* For now we only set the objects on the static types once.
7063
+ * We will relax that once each types __dict__ is per-interpreter. */
7062
7064
#define DATETIME_ADD_MACRO (dict , c , value_expr ) \
7063
7065
do { \
7066
+ if (PyDict_GetItemString(dict, c) == NULL) { \
7067
+ assert(!PyErr_Occurred()); \
7064
7068
PyObject *value = (value_expr); \
7065
7069
if (value == NULL) { \
7066
7070
goto error; \
@@ -7070,6 +7074,7 @@ _datetime_exec(PyObject *module)
7070
7074
goto error; \
7071
7075
} \
7072
7076
Py_DECREF(value); \
7077
+ } \
7073
7078
} while(0)
7074
7079
7075
7080
/* timedelta values */
@@ -7117,6 +7122,8 @@ _datetime_exec(PyObject *module)
7117
7122
PyObject * max = create_timezone_from_delta (0 , (23 * 60 + 59 ) * 60 , 0 , 0 );
7118
7123
DATETIME_ADD_MACRO (d , "max" , max );
7119
7124
7125
+ #undef DATETIME_ADD_MACRO
7126
+
7120
7127
/* Add module level attributes */
7121
7128
if (PyModule_AddIntMacro (module , MINYEAR ) < 0 ) {
7122
7129
goto error ;
@@ -7171,7 +7178,6 @@ _datetime_exec(PyObject *module)
7171
7178
Py_XDECREF (old_module );
7172
7179
return rc ;
7173
7180
}
7174
- #undef DATETIME_ADD_MACRO
7175
7181
7176
7182
static PyModuleDef_Slot module_slots [] = {
7177
7183
{Py_mod_exec , _datetime_exec },
0 commit comments