Fix bytearray append

This commit is contained in:
Kangzhi Shi committed 2020-09-14 16:23:13 +02:00
1 parent a37737b0cd
commit 3397d56f58
3 files changed
+8 -8

No files matched your search

-2
View File
@@ -1507,8 +1507,6 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
def test_nosort(self):
self.assertRaises(AttributeError, lambda: bytearray().sort())
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_append(self):
b = bytearray(b'hell')
b.append(ord('o'))
+6
View File
@@ -436,6 +436,12 @@ impl PyBytesInner {
Ok(())
}
pub fn append(&mut self, object: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let value = Self::value_try_from_object(vm, object)?;
self.elements.push(value);
Ok(())
}
pub fn isalnum(&self) -> bool {
!self.elements.is_empty()
&& self
+2 -6
View File
@@ -1,7 +1,6 @@
//! Implementation of the python bytearray object.
use bstr::ByteSlice;
use crossbeam_utils::atomic::AtomicCell;
use num_traits::cast::ToPrimitive;
use std::mem::size_of;
use super::objint::PyIntRef;
@@ -511,11 +510,8 @@ impl PyByteArray {
}
#[pymethod(name = "append")]
fn append(&self, x: PyIntRef, vm: &VirtualMachine) -> PyResult<()> {
self.borrow_value_mut()
.elements
.push(x.borrow_value().byte_or(vm)?);
Ok(())
fn append(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
self.borrow_value_mut().append(value, vm)
}
#[pymethod(name = "extend")]