Skip to content

Commit

Permalink
gh-111513: Improve datetime.fromtimestamp's error message (#124249)
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk authored Sep 20, 2024
1 parent db6eb36 commit 1a57772
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the error message that may be raised by :meth:`datetime.date.fromtimestamp`.
4 changes: 4 additions & 0 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a57772

Please sign in to comment.