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

This commit is contained in:
AN Long 2024-09-20 20:42:43 +08:00 committed by GitHub
parent db6eb3640a
commit 1a577729e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1 @@
Improve the error message that may be raised by :meth:`datetime.date.fromtimestamp`.

View 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;