Fix byte{s,array}.join

This commit is contained in:
coolreader18 committed 2019-12-03 21:39:33 -06:00
1 parent e5a512cc9a
commit bca6214c4f
5 files changed
+12 -4

No files matched your search

+3
View File
@@ -271,6 +271,9 @@ assert bytearray(b"").join(
) == bytearray(b"jiljlkmoomkaaaa")
with assert_raises(TypeError):
bytearray(b"").join((b"km", "kl"))
assert bytearray(b"abc").join((
bytearray(b"123"), bytearray(b"xyz")
)) == bytearray(b"123abcxyz")
# endswith startswith
+2
View File
@@ -270,6 +270,8 @@ assert (
with assert_raises(TypeError):
b"".join((b"km", "kl"))
assert b"abc".join((b"123", b"xyz")) == b"123abcxyz"
# endswith startswith
assert b"abcde".endswith(b"de")
+1 -1
View File
@@ -290,7 +290,7 @@ impl PyByteArrayRef {
}
#[pymethod(name = "join")]
fn join(self, iter: PyIterable, vm: &VirtualMachine) -> PyResult {
fn join(self, iter: PyIterable<PyByteInner>, vm: &VirtualMachine) -> PyResult {
self.inner.borrow().join(iter, vm)
}
+5 -2
View File
@@ -826,11 +826,14 @@ impl PyByteInner {
Ok(total)
}
pub fn join(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult {
pub fn join(&self, iter: PyIterable<PyByteInner>, vm: &VirtualMachine) -> PyResult {
let mut refs = vec![];
for v in iter.iter(vm)? {
let v = v?;
refs.extend(PyByteInner::try_from_object(vm, v)?.elements)
if !refs.is_empty() {
refs.extend(&self.elements);
}
refs.extend(v.elements);
}
Ok(vm.ctx.new_bytes(refs))
+1 -1
View File
@@ -263,7 +263,7 @@ impl PyBytesRef {
}
#[pymethod(name = "join")]
fn join(self, iter: PyIterable, vm: &VirtualMachine) -> PyResult {
fn join(self, iter: PyIterable<PyByteInner>, vm: &VirtualMachine) -> PyResult {
self.inner.join(iter, vm)
}