diff options
-rw-r--r-- | Lib/test/test_deque.py | 6 | ||||
-rw-r--r-- | Modules/collectionsmodule.c | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index a562922..35e1536 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -396,6 +396,12 @@ class TestVariousIteratorArgs(unittest.TestCase): d.pop() self.assertRaises(RuntimeError, it.next) + def test_runtime_error_on_empty_deque(self): + d = deque() + it = iter(d) + d.append(10) + self.assertRaises(RuntimeError, it.next) + class Deque(deque): pass diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index c1bd732..a0570cd 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -911,15 +911,14 @@ dequeiter_next(dequeiterobject *it) { PyObject *item; - if (it->counter == 0) - return NULL; - if (it->deque->state != it->state) { it->counter = 0; PyErr_SetString(PyExc_RuntimeError, "deque mutated during iteration"); return NULL; } + if (it->counter == 0) + return NULL; assert (!(it->b == it->deque->rightblock && it->index > it->deque->rightindex)); |