Skip to content

Commit 1a57772

Browse files
authored
gh-111513: Improve datetime.fromtimestamp's error message (#124249)
1 parent db6eb36 commit 1a57772

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the error message that may be raised by :meth:`datetime.date.fromtimestamp`.

Python/pytime.c

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ pytime_object_to_denominator(PyObject *obj, time_t *sec, long *numerator,
387387
*sec = _PyLong_AsTime_t(obj);
388388
*numerator = 0;
389389
if (*sec == (time_t)-1 && PyErr_Occurred()) {
390+
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
391+
PyErr_Format(PyExc_TypeError,
392+
"argument must be int or float, not %T", obj);
393+
}
390394
return -1;
391395
}
392396
return 0;

0 commit comments

Comments
 (0)