8000 gh-111513: Improve datetime.fromtimestamp's error message by aisk · Pull Request #124249 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix the right function
  • Loading branch information
aisk committed Sep 19, 2024
commit 076e29f125104b85271aeab109c0f1007ec168f8
3 changes: 1 addition & 2 deletions Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,7 @@ def __new__(cls, year, month=None, day=None):
def fromtimestamp(cls, t):
"Construct a date from a POSIX timestamp (like time.time())."
if t is None:
raise TypeError("'NoneType' object cannot be interpreted "
"as an integer or a float")
raise TypeError("'NoneType' object cannot be interpreted as an integer")
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
return cls(y, m, d)

Expand Down
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
0