Index: Lib/test/test_deque.py =================================================================== --- Lib/test/test_deque.py (revision 88188) +++ Lib/test/test_deque.py (working copy) @@ -138,6 +138,15 @@ m.d = d self.assertRaises(RuntimeError, d.count, 3) + # test issue11004 + # block advance failed after rotation aligned elements on right side of block + d = deque([None]*16) + for i in range(len(d)): + d.rotate(-1) + d.rotate(1) + self.assertEqual(d.count(1), 0) + self.assertEqual(d.count(None), 16) + def test_comparisons(self): d = deque('xabc'); d.popleft() for e in [d, deque('abc'), deque('ab'), deque(), list(d)]: Index: Modules/_collectionsmodule.c =================================================================== --- Modules/_collectionsmodule.c (revision 88188) +++ Modules/_collectionsmodule.c (working copy) @@ -485,7 +485,8 @@ /* Advance left block/index pair */ leftindex++; if (leftindex == BLOCKLEN) { - assert (leftblock->rightlink != NULL); + if (leftblock->rightlink == NULL) + break; leftblock = leftblock->rightlink; leftindex = 0; } @@ -533,7 +534,8 @@ /* Advance left block/index pair */ leftindex++; if (leftindex == BLOCKLEN) { - assert (leftblock->rightlink != NULL); + if (leftblock->rightlink == NULL) + break; leftblock = leftblock->rightlink; leftindex = 0; }