gh-152849: Fix OverflowError message for out-of-range float timestamps#152850
Merged
StanFromIreland merged 5 commits intoJul 6, 2026
Merged
Conversation
…estamps
pytime_from_double() converts a float number of seconds to a PyTime_t
(nanoseconds) but reported overflow with pytime_time_t_overflow()
("out of range for platform time_t"), naming a type it never uses. The
integer path already uses pytime_overflow(); switch the float path to it
so both conversion paths report the same PyTime_t overflow.
sobolevn
reviewed
Jul 2, 2026
StanFromIreland
approved these changes
Jul 6, 2026
StanFromIreland
left a comment
Member
There was a problem hiding this comment.
LGTM
Few little nits.
Co-authored-by: Stan Ulbrych <stan@python.org>
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-153207 is a backport of this pull request to the 3.13 branch. |
|
GH-153208 is a backport of this pull request to the 3.14 branch. |
|
GH-153209 is a backport of this pull request to the 3.15 branch. |
Member
|
Merged, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pytime_from_double()inPython/pytime.cconverts a float number ofseconds to a
PyTime_t(nanoseconds). On overflow it calledpytime_time_t_overflow(), which reports"timestamp out of range for platform time_t"— but this path never converts totime_t. The integerpath,
pytime_from_object(), already reports the same conceptual overflowwith
pytime_overflow()("timestamp too large to convert to C PyTime_t").This swaps the float path to
pytime_overflow()so both paths agree and themessage names the type actually involved. The old wording was wrong in fact,
not only in type:
PyTime_tsaturates at roughly 292 years (int64nanoseconds), while 64-bit
time_tspans far longer, so e.g.time.sleep(1e10)(~317 years) overflowsPyTime_tyet is well withintime_trange — the reportedtime_tlimit was never the actual constraint.The correct helper already exists in the same file, so this is a one-line
change that only affects the message text; it targets
mainonly.User-visible via any float-seconds API, e.g.:
Verified in a build of
main: the_PyTime_FromSecondsObject()float path(and
time.sleep()) now raises thePyTime_tmessage for both positive andnegative out-of-range values, matching the integer path; the full
test_timesuite passes. A regression test asserting the float-path overflowmessage is added to
TestCPyTime(fails before the fix, passes after).time_toverflow message for out-of-range float timestamps inpytime_from_double()#152849