Skip to content
Merged
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
4 changes: 3 additions & 1 deletion Lib/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def get(self, block=True, timeout=None):
available, else raise the Empty exception ('timeout' is ignored
in that case).
'''
if timeout is not None and timeout < 0:
if not block:
timeout = None
elif timeout is not None and timeout < 0:
raise ValueError("'timeout' must be a non-negative number")
if not self._count.acquire(block, timeout):
raise Empty
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ def test_negative_timeout_raises_exception(self):
with self.assertRaises(ValueError):
q.get(timeout=-1)

def test_nonblocking_ignores_timeout(self):
q = self.q
with self.assertRaises(self.queue.Empty):
q.get(block=False, timeout=-1)

def test_order(self):
# Test a pair of concurrent put() and get()
q = self.q
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The pure Python implementation of :meth:`queue.SimpleQueue.get` now ignores
*timeout* when *block* is false, matching the documented behavior and
the C implementation. It previously raised :exc:`ValueError`.
25 changes: 16 additions & 9 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,8 @@ codegen_enter_scope(compiler *c, identifier name, int scope_type,
}

static int
codegen_setup_annotations_scope(compiler *c, location loc,
void *key, PyObject *name)
codegen_emit_annotations_prologue(compiler *c, location loc)
{
_PyCompile_CodeUnitMetadata umd = {
.u_posonlyargcount = 1,
};
RETURN_IF_ERROR(
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
key, loc.lineno, NULL, &umd));

// if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
PyObject *value_with_fake_globals = PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
if (value_with_fake_globals == NULL) {
Expand All @@ -736,6 +728,21 @@ codegen_setup_annotations_scope(compiler *c, location loc,
return SUCCESS;
}

static int
codegen_setup_annotations_scope(compiler *c, location loc,
void *key, PyObject *name)
{
_PyCompile_CodeUnitMetadata umd = {
.u_posonlyargcount = 1,
};
RETURN_IF_ERROR(
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
key, loc.lineno, NULL, &umd));

RETURN_IF_ERROR_IN_SCOPE(c, codegen_emit_annotations_prologue(c, loc));
return SUCCESS;
}

static int
codegen_rename_annotations_format_param(PyCodeObject *co)
{
Expand Down
Loading