-
-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
bpo-32417: Make timedelta arithmetic respect subclasses #10902
bpo-32417: Make timedelta arithmetic respect subclasses #10902
Conversation
42cdcac
to
627d4cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the C code?
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
timedelta
over to returning the subclass it was added to,fromutc
now 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
datetime
anddate
subclasses.https://bugs.python.org/issue32417
https://bugs.python.org/issue35364
https://bugs.python.org/issue32417