https://github.com/python/cpython/commit/1a577729e347714eb819fa3a3a00149406c24e5e
commit: 1a577729e347714eb819fa3a3a00149406c24e5e
branch: main
author: AN Long <[email protected]>
committer: vstinner <[email protected]>
date: 2024-09-20T14:42:43+02:00
summary:

gh-111513: Improve datetime.fromtimestamp's error message (#124249)

files:
A Misc/NEWS.d/next/Library/2024-09-19-16-00-22.gh-issue-111513.6jHm02.rst
M 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
index 00000000000000..c6b85f9cd72255
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-09-19-16-00-22.gh-issue-111513.6jHm02.rst
@@ -0,0 +1 @@
+Improve the error message that may be raised by 
:meth:`datetime.date.fromtimestamp`.
diff --git a/Python/pytime.c b/Python/pytime.c
index cd76970718622f..2b37cd991ef4e4 100644
--- a/Python/pytime.c
+++ b/Python/pytime.c
@@ -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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to