]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111513: Improve datetime.fromtimestamp's error message (#124249)
authorAN Long <aisk@users.noreply.github.com>
Fri, 20 Sep 2024 12:42:43 +0000 (20:42 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2024 12:42:43 +0000 (14:42 +0200)
Misc/NEWS.d/next/Library/2024-09-19-16-00-22.gh-issue-111513.6jHm02.rst [new file with mode: 0644]
Python/pytime.c

diff --git a/Misc/NEWS.d/next/Library/2024-09-19-16-00-22.gh-issue-111513.6jHm02.rst b/Misc/NEWS.d/next/Library/2024-09-19-16-00-22.gh-issue-111513.6jHm02.rst
new file mode 100644 (file)
index 0000000..c6b85f9
--- /dev/null
@@ -0,0 +1 @@
+Improve the error message that may be raised by :meth:`datetime.date.fromtimestamp`.
index cd76970718622f33885001131f7387ed3eb0288f..2b37cd991ef4e44af1155bd59f8719fe011549a5 100644 (file)
@@ -387,6 +387,10 @@ pytime_object_to_denominator(PyObject *obj, time_t *sec, long *numerator,
         *sec = _PyLong_AsTime_t(obj);
         *numerator = 0;
         if (*sec == (time_t)-1 && PyErr_Occurred()) {
+            if (PyErr_ExceptionMatches(PyExc_TypeError)) {
+                PyErr_Format(PyExc_TypeError,
+                             "argument must be int or float, not %T", obj);
+            }
             return -1;
         }
         return 0;