Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
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
5 changes: 5 additions & 0 deletions 5 Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def test_sleep(self):
self.assertRaises(ValueError, time.sleep, -1)
time.sleep(1.2)

def test_sleep_invalid(self):
with self.assertRaisesRegex(
TypeError, 'an integer or float is required'):
time.sleep('foo')

def test_strftime(self):
tt = time.gmtime(self.t)
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
Expand Down
6 changes: 5 additions & 1 deletion 6 Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ static int
_PyTime_FromObject(_PyTime_t *t, PyObject *obj, _PyTime_round_t round,
long unit_to_ns)
{
if (PyFloat_Check(obj)) {
if (!PyFloat_Check(obj) && !PyLong_Check(obj)) {

@iritkatriel iritkatriel Sep 17, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. In the else case below it calls PyLong_AsLongLong, which can handle values which are not PyLongs as long as they can be converted to a PyLong via _PyNumber_Index.

If this change didn't break any unit tests, then a test is probably missing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see you've commented on that. Sorry for the noise.

PyErr_SetString(PyExc_TypeError, "an integer or float is required.");
return -1;
}
else if (PyFloat_Check(obj)) {
double d;
d = PyFloat_AsDouble(obj);
if (Py_IS_NAN(d)) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.