bpo-32417: Make timedelta arithmetic respect subclasses#10902
bpo-32417: Make timedelta arithmetic respect subclasses#10902abalkin merged 7 commits intopython:masterfrom
Conversation
42cdcac to
627d4cb
Compare
vstinner
left a comment
There was a problem hiding this comment.
LGTM, but I would prefer to see a review from a second core dev. @serhiy-storchaka, @abalkin, @pablogsal maybe?
627d4cb to
8c784f8
Compare
|
@vstinner Thanks for your comments, sorry for the delay in addressing them - I put it off for a bit because this change likely needs wider discussion and I haven't had time to have that discussion with python-dev before now. I've addressed your style concerns, rebased against master and started a thread on python-dev for discussion. |
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.
Fixes: bpo-32417 bpo-35364
Addresses Victor's comments
8c784f8 to
598b665
Compare
|
@gvanrossum That's the first commit, it's here (at the bottom of the diff). It's just a matter of switching to the C function that constructs either a |
gvanrossum
left a comment
There was a problem hiding this comment.
Sorry I missed the C code at first! Reviewing on a phone is not ideal. All looks good. Go ahead and merge!
|
@abalkin: Please replace |
This fixes both bpo-35364 and bpo-32417. See this comment for a detailed rationale.
By changing
timedeltaover to returning the subclass it was added to,fromutcnow also respects the subclass of the datetime being converted, and consequently so do all thetz=...forms of the alternate constructors.This will fix many major headaches for people implementing
datetimeanddatesubclasses.https://bugs.python.org/issue32417
https://bugs.python.org/issue35364
https://bugs.python.org/issue32417