GH-121832: Assert that the version number of static builtin types is not changed by PyType_Modified. (GH-122182)
Update datetime module and test_type_cache.py to not call PyType_Modified.
This commit is contained in:
@@ -7256,50 +7256,52 @@ _datetime_exec(PyObject *module)
|
||||
Py_DECREF(value); \
|
||||
} while(0)
|
||||
|
||||
/* timedelta values */
|
||||
PyObject *d = _PyType_GetDict(&PyDateTime_DeltaType);
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
DATETIME_ADD_MACRO(d, "min", new_delta(-MAX_DELTA_DAYS, 0, 0, 0));
|
||||
DATETIME_ADD_MACRO(d, "max",
|
||||
new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0));
|
||||
if (!reloading) {
|
||||
/* timedelta values */
|
||||
PyObject *d = _PyType_GetDict(&PyDateTime_DeltaType);
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
DATETIME_ADD_MACRO(d, "min", new_delta(-MAX_DELTA_DAYS, 0, 0, 0));
|
||||
DATETIME_ADD_MACRO(d, "max",
|
||||
new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0));
|
||||
|
||||
/* date values */
|
||||
d = _PyType_GetDict(&PyDateTime_DateType);
|
||||
DATETIME_ADD_MACRO(d, "min", new_date(1, 1, 1));
|
||||
DATETIME_ADD_MACRO(d, "max", new_date(MAXYEAR, 12, 31));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(1, 0, 0, 0));
|
||||
/* date values */
|
||||
d = _PyType_GetDict(&PyDateTime_DateType);
|
||||
DATETIME_ADD_MACRO(d, "min", new_date(1, 1, 1));
|
||||
DATETIME_ADD_MACRO(d, "max", new_date(MAXYEAR, 12, 31));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(1, 0, 0, 0));
|
||||
|
||||
/* time values */
|
||||
d = _PyType_GetDict(&PyDateTime_TimeType);
|
||||
DATETIME_ADD_MACRO(d, "min", new_time(0, 0, 0, 0, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "max", new_time(23, 59, 59, 999999, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
/* time values */
|
||||
d = _PyType_GetDict(&PyDateTime_TimeType);
|
||||
DATETIME_ADD_MACRO(d, "min", new_time(0, 0, 0, 0, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "max", new_time(23, 59, 59, 999999, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
|
||||
/* datetime values */
|
||||
d = _PyType_GetDict(&PyDateTime_DateTimeType);
|
||||
DATETIME_ADD_MACRO(d, "min",
|
||||
new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "max", new_datetime(MAXYEAR, 12, 31, 23, 59, 59,
|
||||
999999, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
/* datetime values */
|
||||
d = _PyType_GetDict(&PyDateTime_DateTimeType);
|
||||
DATETIME_ADD_MACRO(d, "min",
|
||||
new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "max", new_datetime(MAXYEAR, 12, 31, 23, 59, 59,
|
||||
999999, Py_None, 0));
|
||||
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
|
||||
|
||||
/* timezone values */
|
||||
d = _PyType_GetDict(&PyDateTime_TimeZoneType);
|
||||
if (PyDict_SetItemString(d, "utc", (PyObject *)&utc_timezone) < 0) {
|
||||
goto error;
|
||||
/* timezone values */
|
||||
d = _PyType_GetDict(&PyDateTime_TimeZoneType);
|
||||
if (PyDict_SetItemString(d, "utc", (PyObject *)&utc_timezone) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* bpo-37642: These attributes are rounded to the nearest minute for backwards
|
||||
* compatibility, even though the constructor will accept a wider range of
|
||||
* values. This may change in the future.*/
|
||||
|
||||
/* -23:59 */
|
||||
DATETIME_ADD_MACRO(d, "min", create_timezone_from_delta(-1, 60, 0, 1));
|
||||
|
||||
/* +23:59 */
|
||||
DATETIME_ADD_MACRO(
|
||||
d, "max", create_timezone_from_delta(0, (23 * 60 + 59) * 60, 0, 0));
|
||||
}
|
||||
|
||||
/* bpo-37642: These attributes are rounded to the nearest minute for backwards
|
||||
* compatibility, even though the constructor will accept a wider range of
|
||||
* values. This may change in the future.*/
|
||||
|
||||
/* -23:59 */
|
||||
DATETIME_ADD_MACRO(d, "min", create_timezone_from_delta(-1, 60, 0, 1));
|
||||
|
||||
/* +23:59 */
|
||||
DATETIME_ADD_MACRO(
|
||||
d, "max", create_timezone_from_delta(0, (23 * 60 + 59) * 60, 0, 0));
|
||||
|
||||
#undef DATETIME_ADD_MACRO
|
||||
|
||||
/* Add module level attributes */
|
||||
@@ -7342,12 +7344,6 @@ _datetime_exec(PyObject *module)
|
||||
static_assert(DI100Y == 25 * DI4Y - 1, "DI100Y");
|
||||
assert(DI100Y == days_before_year(100+1));
|
||||
|
||||
if (reloading) {
|
||||
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
|
||||
PyType_Modified(capi_types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (set_current_module(interp, module) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user