[pypy-commit] pypy py3.5: merge heads
arigo
pypy.commits at gmail.com
Tue Oct 18 04:47:18 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r87854:b34556478b94
Date: 2016-10-18 10:46 +0200
http://bitbucket.org/pypy/pypy/changeset/b34556478b94/
Log: merge heads
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
@@ -177,6 +177,7 @@
def add(self, w_iterable):
copy = W_Deque(self.space)
+ copy.maxlen = self.maxlen
copy.extend(self.iter())
copy.extend(w_iterable)
return self.space.wrap(copy)
@@ -188,6 +189,7 @@
def mul(self, w_int):
space = self.space
copied = W_Deque(space)
+ copied.maxlen = self.maxlen
num = space.int_w(w_int)
for _ in range(num):
@@ -200,9 +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)
@@ -372,13 +381,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
@@ -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
@@ -386,3 +392,28 @@
d = deque([1,2])
assert 2 * d == deque([1,2,1,2])
assert -5 * d == deque()
+
+ def test_deque_maxlen(self):
+ from _collections import deque
+ g = deque('abcdef', maxlen=4)
+ assert len(g) == 4 and g == deque('cdef')
+ h = deque('gh')
+ 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
+
+ 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
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -902,13 +902,12 @@
if space.isinstance_w(w_value, space.w_unicode):
from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
s = unicode_to_decimal_w(space, w_value, allow_surrogates=True)
+ elif (space.isinstance_w(w_value, space.w_bytes) or
+ space.isinstance_w(w_value, space.w_bytearray)):
+ s = space.bufferstr_w(w_value)
else:
- try:
- s = space.bufferstr_w(w_value)
- except OperationError as e:
- raise oefmt(space.w_TypeError,
- "int() can't convert non-string with explicit "
- "base")
+ raise oefmt(space.w_TypeError,
+ "int() can't convert non-string with explicit base")
return _string_to_int_or_long(space, w_inttype, w_value, s, base)
diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -602,6 +602,11 @@
assert m is False
assert len(log) == 2
+ def test_int_nonstr_with_base(self):
+ assert int(b'100', 2) == 4
+ assert int(bytearray(b'100'), 2) == 4
+ raises(TypeError, int, memoryview(b'100'), 2)
+
class AppTestIntShortcut(AppTestInt):
spaceconfig = {"objspace.std.intshortcut": True}
More information about the pypy-commit
mailing list