Author: Richard Plangger <planri...@gmail.com>
Branch: py3.5
Changeset: r87845:00590aa7234c
Date: 2016-10-17 15:36 +0200
http://bitbucket.org/pypy/pypy/changeset/00590aa7234c/

Log:    special case in imul

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
@@ -202,10 +202,16 @@
 
     def imul(self, w_int):
         space = self.space
+        num = space.int_w(w_int)
+        if self.len == 0 or num == 1:
+            return space.wrap(self)
+        if num <= 0:
+            self.clear()
+            return space.wrap(self)
+        # use a copy to extend self
         copy = W_Deque(space)
         copy.maxlen = self.maxlen
         copy.extend(self.iter())
-        num = space.int_w(w_int)
 
         for _ in range(num - 1):
             self.extend(copy)
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
@@ -350,6 +350,12 @@
         d *= 3
         assert d == deque([1,2,3]*3)
         assert d is not deque([1,2,3]*3)
+        d = deque('a')
+        for n in (-10, -1, 0, 1, 2, 10, 1000):
+            d = deque('a')
+            d *= n
+            assert d == deque('a' * n)
+            assert d.maxlen is None
 
     def test_deque_insert(self):
         from _collections import deque
@@ -405,3 +411,9 @@
             s.insert(i, 'Z')
             assert list(d) == s
 
+    def test_deque_index_overflow_start_end(self):
+        from _collections import deque
+        import sys
+        elements = 'ABCDEFGHI'
+        d = deque([-2, -1, 0, 0, 1, 2])
+        assert a.index(0, -4*sys.maxsize, 4*sys.maxsize) == 2
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to