diff options
author | Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> | 2025-03-12 08:12:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-12 08:12:57 +0000 |
commit | 155c44b9015089eacc6e2ace449391c12bfb8b8d (patch) | |
tree | 90b09e071ca5fdcfc9bbbf3aa87120d63eee864d /Python/pytime.c | |
parent | 15a8412b5e12ae46761843d4442c7b56ffa75176 (diff) | |
download | cpython-155c44b9015089eacc6e2ace449391c12bfb8b8d.tar.gz cpython-155c44b9015089eacc6e2ace449391c12bfb8b8d.zip |
gh-81267: Correct time.sleep() error message (#131055)
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index b10d5cf927b..2ca92037c2e 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -594,26 +594,30 @@ pytime_from_object(PyTime_t *tp, PyObject *obj, _PyTime_round_t round, } return pytime_from_double(tp, d, round, unit_to_ns); } - else { - long long sec = PyLong_AsLongLong(obj); - if (sec == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - pytime_overflow(); - } - return -1; - } - static_assert(sizeof(long long) <= sizeof(PyTime_t), - "PyTime_t is smaller than long long"); - PyTime_t ns = (PyTime_t)sec; - if (pytime_mul(&ns, unit_to_ns) < 0) { + long long sec = PyLong_AsLongLong(obj); + if (sec == -1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { pytime_overflow(); - return -1; } + else if (PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Format(PyExc_TypeError, + "'%T' object cannot be interpreted as an integer or float", + obj); + } + return -1; + } - *tp = ns; - return 0; + static_assert(sizeof(long long) <= sizeof(PyTime_t), + "PyTime_t is smaller than long long"); + PyTime_t ns = (PyTime_t)sec; + if (pytime_mul(&ns, unit_to_ns) < 0) { + pytime_overflow(); + return -1; } + + *tp = ns; + return 0; } |