diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 1850f053aaffd6..5e068c2c02dfd2 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -1013,6 +1013,18 @@ 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 _testcapi import PyTime_MIN, PyTime_MAX + from _testinternalcapi import _PyTime_FromSecondsObject + for value in (float(PyTime_MAX), float(PyTime_MIN)): + for time_rnd, _ in ROUNDING_MODES: + 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 diff --git a/Misc/NEWS.d/next/Library/2026-07-02-13-30-00.gh-issue-152849.K9dRvP.rst b/Misc/NEWS.d/next/Library/2026-07-02-13-30-00.gh-issue-152849.K9dRvP.rst new file mode 100644 index 00000000000000..b2f1ab1426ce50 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-02-13-30-00.gh-issue-152849.K9dRvP.rst @@ -0,0 +1,2 @@ +Fix the :exc:`OverflowError` message for out-of-range float timestamps: it +now names ``PyTime_t`` instead of ``time_t``. Patch by tonghuaroot. diff --git a/Python/pytime.c b/Python/pytime.c index 399ff59ad01ab6..53c82736137a16 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -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"); } @@ -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)) { - pytime_time_t_overflow(); + pytime_overflow(); *tp = 0; return -1; }