mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Fix bytearray append
This commit is contained in:
1 parent
a37737b0cd
commit
3397d56f58
3 files changed
+8
-8
No files matched your search
@@ -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'))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in new issue
Block a user