8000 gh-89039: call subclass constructors in datetime.*.replace by eltoder · Pull Request #114780 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-89039: call subclass constructors in datetime.*.replace #114780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address comments
  • Loading branch information
eltoder committed Jan 31, 2024
commit 6dfba7f2433986be93dca92e8391eea5a7cb7f94
13 changes: 8 additions & 5 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,8 @@ new_datetime_ex(int year, int month, int day, int hour, int minute,
&PyDateTime_DateTimeType)

static PyObject *
call_subclass_fold(PyObject *cls, int fold, const char *format, ...) {
call_subclass_fold(PyObject *cls, int fold, const char *format, ...)
{
PyObject *kwargs = NULL, *res = NULL;
va_list va;

Expand All @@ -1065,9 +1066,9 @@ call_subclass_fold(PyObject *cls, int fold, const char *format, ...) {
if (obj == NULL) {
goto Done;
}
int res = PyDict_SetItemString(kwargs, "fold", obj);
int err = PyDict_SetItemString(kwargs, "fold", obj);
Py_DECREF(obj);
if (res < 0) {
if (err < 0) {
goto Done;
}
}
Expand All @@ -1087,7 +1088,8 @@ new_datetime_subclass_fold_ex(int year, int month, int day, int hour, int minute
// Use the fast path constructor
dt = new_datetime(year, month, day, hour, minute, second, usecond,
tzinfo, fold);
} else {
}
else {
// Subclass
dt = call_subclass_fold(cls, fold, "iiiiiiiO", year, month, day,
hour, minute, second, usecond, tzinfo);
Expand Down Expand Up @@ -1154,7 +1156,8 @@ new_time_subclass_fold_ex(int hour, int minute, int second, int usecond,
if ((PyTypeObject*)cls == &PyDateTime_TimeType) {
// Use the fast path constructor
t = new_time(hour, minute, second, usecond, tzinfo, fold);
} else {
}
else {
// Subclass
t = call_subclass_fold(cls, fold, "iiiiO", hour, minute, second,
usecond, tzinfo);
Expand Down
0