Skip to content
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
8 changes: 6 additions & 2 deletions Lib/test/test_interpreters/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_create_destroy(self):
with self.assertRaises(queues.QueueNotFoundError):
_queues.destroy(qid)

with self.assertRaises(ValueError):
# gh-135698: max_size must be greater than or equal to 0
_queues.create(-1, 1, 1)

def test_not_destroyed(self):
# It should have cleaned up any remaining queues.
stdout, stderr = self.assert_python_ok(
Expand Down Expand Up @@ -114,8 +118,8 @@ def test_create(self):
self.assertEqual(queue.maxsize, 0)

with self.subTest('negative maxsize'):
queue = queues.create(-10)
self.assertEqual(queue.maxsize, -10)
with self.assertRaises(ValueError):
queues.create(-10)

with self.subTest('bad maxsize'):
with self.assertRaises(TypeError):
Expand Down
5 changes: 5 additions & 0 deletions Modules/_interpqueuesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,11 @@ queuesmod_create(PyObject *self, PyObject *args, PyObject *kwds)
{
return NULL;
}
if (maxsize < 0) {
PyErr_SetString(PyExc_ValueError,
"max_size must be greater than or equal to 0");
return NULL;
}
Comment on lines +1491 to +1495
Copy link
Copy Markdown
Member

@ericsnowcurrently ericsnowcurrently Jun 19, 2025

Choose a reason for hiding this comment

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

A negative value is fine. That's the same as queue.Queue. The logic (and the assert) in _queue_is_full() is actually wrong. I'll put up a PR.

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.

See gh-135724.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh I see! I closed my PR.

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.

Thanks for taking time on this!

struct _queuedefaults defaults = {0};
if (resolve_unboundop(unboundarg, UNBOUND_REPLACE,
&defaults.unboundop) < 0)
Expand Down
Loading