[pypy-commit] pypy py3.5: return on some path to not insert the element twice (deque.insert)
plan_rich
pypy.commits at gmail.com
Mon Oct 17 09:37:33 EDT 2016
Author: Richard Plangger <planrichi at 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
+
More information about the pypy-commit
mailing list