mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-32417: Make timedelta arithmetic respect subclasses (#10902)
* Make timedelta return subclass types Previously timedelta would always return the `date` and `datetime` types, regardless of what it is added to. This makes it return an object of the type it was added to. * Add tests for timedelta arithmetic on subclasses * Make pure python timedelta return subclass types * Add test for fromtimestamp with tz argument * Add tests for subclass behavior in now * Add news entry. Fixes: bpo-32417 bpo-35364 * More descriptive variable names in tests Addresses Victor's comments
This commit is contained in:
parent
ca7d2933a3
commit
89427cd0fe
4 changed files with 90 additions and 19 deletions
|
@ -3004,7 +3004,8 @@ add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
|
|||
int day = GET_DAY(date) + (negate ? -deltadays : deltadays);
|
||||
|
||||
if (normalize_date(&year, &month, &day) >= 0)
|
||||
result = new_date(year, month, day);
|
||||
result = new_date_subclass_ex(year, month, day,
|
||||
(PyObject* )Py_TYPE(date));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -5166,9 +5167,10 @@ add_datetime_timedelta(PyDateTime_DateTime *date, PyDateTime_Delta *delta,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return new_datetime(year, month, day,
|
||||
hour, minute, second, microsecond,
|
||||
HASTZINFO(date) ? date->tzinfo : Py_None, 0);
|
||||
return new_datetime_subclass_ex(year, month, day,
|
||||
hour, minute, second, microsecond,
|
||||
HASTZINFO(date) ? date->tzinfo : Py_None,
|
||||
(PyObject *)Py_TYPE(date));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue