]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-152849: Fix `OverflowError` message for out-of-range timestamps in the...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Jul 2026 15:16:34 +0000 (17:16 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2026 15:16:34 +0000 (15:16 +0000)
(cherry picked from commit 2d7a74ece7884c9a5f52cc6ac38a6e7ee691b26c)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Lib/test/test_time.py
Misc/NEWS.d/next/Library/2026-07-02-13-30-00.gh-issue-152849.K9dRvP.rst [new file with mode: 0644]
Python/pytime.c

index f66a37edb4cadfccd20a4dc244a7a3a1e0fa4142..ff7d982fb3621c0e7eb3ffba2c3884f1e619d1a1 100644 (file)
@@ -977,6 +977,17 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase):
             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:
+                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 (file)
index 0000000..053a5df
--- /dev/null
@@ -0,0 +1,2 @@
+Out-of-range float and integer timestamps now raise :exc:`OverflowError`
+with the same message. Patch by tonghuaroot.
index 67cf643726449096c54de3e451f8044f5e9c64fc..894f6e7ca54c3ebde70e358ec3223ba8b7fe670b 100644 (file)
@@ -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");
 }
 
 
@@ -571,7 +571,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;
     }