-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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-30516: Fix documentation issue with -timedelta in datetime #7348
bpo-30516: Fix documentation issue with -timedelta in datetime #7348
Conversation
Doc/library/datetime.rst
Outdated
@@ -317,6 +317,11 @@ Notes: | |||
>>> print(_) | |||
-1 day, 19:00:00 | |||
|
|||
(6) | |||
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in | |||
isolation can overflow in cases where date1 - timedelta does not. |
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.
Should say "in cases where timedelta - timedelta
does not"
Doc/library/datetime.rst
Outdated
(6) | ||
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in | ||
isolation can overflow in cases where date1 - timedelta does not. | ||
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored. |
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.
I think this part is only true for date2 = date1 - timedelta
, and that part of the original footnote probably needs to remain in the "supported operations" section for datetime.date
.
I made a few notes. I'm somewhat ambivalent about including the footnote at all, since it's already covered by the notes on |
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.
+1 on @pganssle comments
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
eb26aaa
to
7906aa6
Compare
Doc/library/datetime.rst
Outdated
This isn't quite equivalent to date1 + (-timedelta), because -timedelta in | ||
isolation can overflow in cases where date1 - timedelta does not. | ||
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored. | ||
timedelta.seconds and timedelta.microseconds are ignored. |
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.
Just a note that has changed from:
`timedelta.seconds` and `timedelta.microseconds` are ignored
In the original they were in code blocks, but the documentation doesn't seem terribly consistent on this point. We should probably pick one and stick with it.
A cursory look at the rest of the documentation seems to indicate that "timedelta.X
" is more common than "timedelta.X", but not by much, and often in expressions.
7906aa6
to
25b5980
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @abalkin: please review the changes made to this pull request. |
Doc/library/datetime.rst
Outdated
This isn't quite equivalent to date1 + (-timedelta), because -timedelta in | ||
isolation can overflow in cases where date1 - timedelta does not. | ||
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored. | ||
``timedelta.seconds and timedelta.microseconds are ignored.`` |
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.
Should be:
timedelta.seconds
and timedelta.microseconds
are ignored.
(Raw RST version):
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
25b5980
to
cc4b3d8
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @abalkin: please review the changes made to this pull request. |
Doc/library/datetime.rst
Outdated
@@ -317,6 +317,10 @@ Notes: | |||
>>> print(_) | |||
-1 day, 19:00:00 | |||
|
|||
(6) | |||
This isn't quite equivalent to timedelta + (-timedelta), because -timedelta in | |||
isolation can overflow in cases where timedelta - timedelta does not. |
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.
Which timedelta is which. Wouldn’t it make more sense to keep using t2 and t3?
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.
I'm not sure it makes much difference which one is which:
The issue is that t1 - t2 == t1 + (-t2)
for all cases except when t2
is timedelta.max
, in which case the right side of the equation overflows before the subtraction because (-timedelta)
is only valid on the interval (-timedelta.max, timedelta.max]
. This is why timedelta + (-timedelta)
and timedelta - timedelta
are not equivalent.
On the other hand, if you interpret it as Python code timedelta + (-timedelta)
would suggest the addition of the type
objects themselves, and I don't think it would hurt to switch over to t1
, t2
and t3
to make it clear that these are specific instances.
@abalkin Thoughts?
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.
I agree that it best to follow the notation used in the body of the table in footnotes. How is this wording?
The expression
t1 - t2
is not always the same ast1 + (-t2)
. In the case whent2
istimedelta.max
,(-t2)
in the second expression will overflow, while the first expression will produce an answer.
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.
This actually makes things clearer, let me make this change and see how it looks.
cc4b3d8
to
875b530
Compare
Doc/library/datetime.rst
Outdated
@@ -317,6 +317,11 @@ Notes: | |||
>>> print(_) | |||
-1 day, 19:00:00 | |||
|
|||
(6) | |||
The expression `t2 - t3` will always be equal to the expression `t2 + (-t3)` except | |||
one condition when t3 is equal to `timedelta.max`, in that condition the former will produce result |
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.
Are you sure you want to repeat the word "condition" here? Why not simply "except when t3 is equal to timedelta.max
, in that case ..."
Also, I feel you need an "a" before "result".
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.
point
875b530
to
4cf21e6
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @abalkin: please review the changes made to this pull request. |
I can't figure out why are tests failing here |
@farhaanbukhsh The test is failing because you're using single backticks instead of double backticks. In restructuredText, surrounding something with single backticks uses the "default role" (which is not |
Doc/library/datetime.rst
Outdated
The expression `t2 - t3` will always be equal to the expression `t2 + (-t3)` except | ||
one condition when t3 is equal to `timedelta.max`, in that case the former will produce a result | ||
while the latter will overflow. | ||
|
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.
To fix the tests use:
(6)
The expression ``t2 - t3`` will always be equal to the expression ``t2 + (-t3)`` except
one condition when t3 is equal to ``timedelta.max``, in that case the former will produce a result
while the latter will overflow.
I'll also note that "except one condition when" doesn't sound like idiomatic English to me. I would say "except the case where" or "except when t3
is equal to timedelta.max
".
I also think the comma after timedelta.max
should probably be a semicolon.
This commit fixes the -timedelta overfllow issue not documented properly. Signed-off-by: Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
4cf21e6
to
dec4bff
Compare
I have made the requested changes; please review again |
Thanks for making the requested changes! @abalkin: please review the changes made to this pull request. |
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.
@farhaanbukhsh Thanks for dealing with all the pickiness! It's patient people like you who make CPython the high quality software that it is.
I think this can be backported to 3.7, probably 3.6 as well. |
@pganssle Thank it means a lot coming from you 😄, although I keep on looking for issues to solve. |
Thanks @farhaanbukhsh for the PR, and @abalkin for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Thanks @farhaanbukhsh for the PR, and @abalkin for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
GH-8092 is a backport of this pull request to the 3.6 branch. |
GH-8093 is a backport of this pull request to the 3.7 branch. |
This commit fixes the -timedelta overfllow issue not documented properly.
Signed-off-by: Farhaan Bukhsh farhaan.bukhsh@gmail.com
https://bugs.python.org/issue30516