Commit 27df1a77 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #832 from vinzenz/bytearray-string-concat

Allow string + bytearray => bytearray. Fixes #780
parents 60850a52 a8e6299a
...@@ -342,10 +342,16 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) { ...@@ -342,10 +342,16 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) {
} }
if (!PyString_Check(_rhs)) { if (!PyString_Check(_rhs)) {
// Note: this is deliberately not returning NotImplemented, even though if (PyByteArray_Check(_rhs)) {
// that would be more usual. I assume this behavior of CPython's is Box* rtn = PyByteArray_Concat(lhs, _rhs);
// for backwards compatibility. checkAndThrowCAPIException();
raiseExcHelper(TypeError, "cannot concatenate 'str' and '%s' objects", getTypeName(_rhs)); return rtn;
} else {
// Note: this is deliberately not returning NotImplemented, even though
// that would be more usual. I assume this behavior of CPython's is
// for backwards compatibility.
raiseExcHelper(TypeError, "cannot concatenate 'str' and '%s' objects", getTypeName(_rhs));
}
} }
BoxedString* rhs = static_cast<BoxedString*>(_rhs); BoxedString* rhs = static_cast<BoxedString*>(_rhs);
......
assert(('abc' + bytearray('def')) == bytearray('abcdef'))
assert((bytearray('abc') + 'def') == bytearray('abcdef'))
try:
u'abc' + bytearray('def')
assert(False)
except TypeError:
pass
try:
bytearray('abc') + u'def'
assert(False)
except TypeError:
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment