[pypy-commit] pypy default: Test and fix
arigo
noreply at buildbot.pypy.org
Thu Nov 13 10:26:53 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r74497:f175883d10c1
Date: 2014-11-13 10:26 +0100
http://bitbucket.org/pypy/pypy/changeset/f175883d10c1/
Log: Test and fix
diff --git a/pypy/objspace/std/strbufobject.py b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -5,6 +5,7 @@
from pypy.objspace.std.bytesobject import (W_AbstractBytesObject,
W_BytesObject, StringBuffer)
from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
from rpython.rlib.rstring import StringBuilder
@@ -46,15 +47,18 @@
return space.wrap(self.length)
def descr_add(self, space, w_other):
+ try:
+ other = W_BytesObject._op_val(space, w_other)
+ except OperationError as e:
+ if e.match(space, space.w_TypeError):
+ return space.w_NotImplemented
+ raise
if self.builder.getlength() != self.length:
builder = StringBuilder()
builder.append(self.force())
else:
builder = self.builder
- if isinstance(w_other, W_StringBufferObject):
- builder.append(w_other.force())
- else:
- builder.append(w_other._value)
+ builder.append(other)
return W_StringBufferObject(builder)
def descr_str(self, space):
diff --git a/pypy/objspace/std/test/test_strbufobject.py b/pypy/objspace/std/test/test_strbufobject.py
--- a/pypy/objspace/std/test/test_strbufobject.py
+++ b/pypy/objspace/std/test/test_strbufobject.py
@@ -78,3 +78,8 @@
c = '0'.__add__('1')
x = c + a
assert x == '01ab'
+
+ def test_add_non_string(self):
+ a = 'a'
+ a += 'b'
+ raises(TypeError, "a += 5")
More information about the pypy-commit
mailing list