mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
@@ -497,8 +497,6 @@ class BaseTest:
|
||||
b = array.array(self.typecode, a)
|
||||
self.assertEqual(a, b)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_repr(self):
|
||||
a = array.array(self.typecode, 2*self.example)
|
||||
self.assertEqual(a, eval(repr(a), {"array": array.array}))
|
||||
|
||||
@@ -236,6 +236,20 @@ macro_rules! def_array_enum {
|
||||
}
|
||||
}
|
||||
|
||||
fn repr(&self, _vm: &VirtualMachine) -> PyResult<String> {
|
||||
// we don't need ReprGuard here
|
||||
let s = match self {
|
||||
$(ArrayContentType::$n(v) => {
|
||||
if v.is_empty() {
|
||||
format!("array('{}')", $c)
|
||||
} else {
|
||||
format!("array('{}', [{}])", $c, v.iter().format(", "))
|
||||
}
|
||||
})*
|
||||
};
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
fn iter<'a>(&'a self, vm: &'a VirtualMachine) -> impl Iterator<Item = PyObjectRef> + 'a {
|
||||
let mut i = 0;
|
||||
std::iter::from_fn(move || {
|
||||
@@ -443,6 +457,11 @@ impl PyArray {
|
||||
self.borrow_value_mut().setitem(needle, obj, vm)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__repr__")]
|
||||
fn repr(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<String> {
|
||||
zelf.borrow_value().repr(vm)
|
||||
}
|
||||
|
||||
#[pymethod(name = "__eq__")]
|
||||
fn eq(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyComparisonValue> {
|
||||
let lhs = self.borrow_value();
|
||||
|
||||
Reference in New Issue
Block a user