From 1a577729e347714eb819fa3a3a00149406c24e5e Mon Sep 17 00:00:00 2001 From: AN Long Date: Fri, 20 Sep 2024 20:42:43 +0800 Subject: gh-111513: Improve datetime.fromtimestamp's error message (#124249) --- Python/pytime.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Python/pytime.c') diff --git a/Python/pytime.c b/Python/pytime.c index cd769707186..2b37cd991ef 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; -- cgit v1.2.3