FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-152849: Fix OverflowError message for out-of-range float timestamps by tonghuaroot · Pull Request #152850 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions Lib/test/test_time.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,17 @@ def test_FromSecondsObject(self):
with self.assertRaises(ValueError):
_PyTime_FromSecondsObject(float('nan'), time_rnd)

def test_FromSecondsObject_float_overflow_message(self):
# Float path must report a PyTime_t overflow, like the integer path.
from _testinternalcapi import _PyTime_FromSecondsObject
for value in (PyTime_MAX, PyTime_MIN):
for time_rnd, _ in ROUNDING_MODES:
Comment thread
sobolevn marked this conversation as resolved.
with self.subTest(value=value, time_rnd=time_rnd):
with self.assertRaisesRegex(
OverflowError,
"timestamp out of range for C PyTime_t"):
_PyTime_FromSecondsObject(value, time_rnd)

def test_AsSecondsDouble(self):
from _testcapi import PyTime_AsSecondsDouble

Expand Down
Comment thread
StanFromIreland marked this conversation as resolved.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Out-of-range float and integer timestamps now raise :exc:`OverflowError`
with the same message. Patch by tonghuaroot.
4 changes: 2 additions & 2 deletions Python/pytime.c
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void
pytime_overflow(void)
{
PyErr_SetString(PyExc_OverflowError,
"timestamp too large to convert to C PyTime_t");
"timestamp out of range for C PyTime_t");
}


Expand Down Expand Up @@ -636,7 +636,7 @@ pytime_from_double(PyTime_t *tp, double value, _PyTime_round_t round,

/* See comments in pytime_double_to_denominator */
if (!((double)PyTime_MIN <= d && d < -(double)PyTime_MIN)) {
Comment thread
StanFromIreland marked this conversation as resolved.
pytime_time_t_overflow();
pytime_overflow();
*tp = 0;
return -1;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL