Author: Richard Plangger <planri...@gmail.com> Branch: py3.5 Changeset: r87844:64d7a3293760 Date: 2016-10-17 15:14 +0200 http://bitbucket.org/pypy/pypy/changeset/64d7a3293760/
Log: return on some path to not insert the element twice (deque.insert) diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -375,13 +375,15 @@ def insert(self, index, w_value): space = self.space n = space.len_w(self) - if n == self.maxlen: + if n >= self.maxlen: raise oefmt(space.w_IndexError, "deque already at its maximum size") if index >= n: self.append(w_value) + return if index <= -n or index == 0: self.appendleft(w_value) + return self.rotate(-index) if index < 0: diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py --- a/pypy/module/_collections/test/test_deque.py +++ b/pypy/module/_collections/test/test_deque.py @@ -395,3 +395,13 @@ assert ''.join(g + h) == 'efgh' assert g + h == deque('efgh') + def test_deque_insert2(self): + from _collections import deque + elements = 'ABCDEFGHI' + for i in range(-5 - len(elements)*2, 5 + len(elements) * 2): + d = deque('ABCDEFGHI') + s = list('ABCDEFGHI') + d.insert(i, 'Z') + s.insert(i, 'Z') + assert list(d) == s + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit