Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
5 changes: 5 additions & 0 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ 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 %.200s",
Py_TYPE(obj)->tp_name);
}
return -1;
}
return 0;
Expand Down
Loading