Fix return types

This commit is contained in:
Jeong YunWon
2020-12-07 03:54:29 +09:00
parent 1c12a80682
commit d15da722ce
9 changed files with 23 additions and 41 deletions

View File

@@ -545,11 +545,11 @@ impl PyByteArray {
}
#[pymethod(name = "splitlines")]
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyResult {
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef {
let lines = self
.borrow_value()
.splitlines(options, |x| vm.ctx.new_bytearray(x.to_vec()));
Ok(vm.ctx.new_list(lines))
vm.ctx.new_list(lines)
}
#[pymethod(name = "zfill")]
@@ -607,9 +607,8 @@ impl PyByteArray {
}
#[pymethod(name = "reverse")]
fn reverse(&self) -> PyResult<()> {
fn reverse(&self) {
self.borrow_value_mut().elements.reverse();
Ok(())
}
#[pymethod]

View File

@@ -118,8 +118,8 @@ impl PyBytes {
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self) -> PyResult<usize> {
Ok(size_of::<Self>() + self.inner.elements.len() * size_of::<u8>())
fn sizeof(&self) -> usize {
size_of::<Self>() + self.inner.elements.len() * size_of::<u8>()
}
#[pymethod(name = "__add__")]
@@ -387,11 +387,11 @@ impl PyBytes {
}
#[pymethod(name = "splitlines")]
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyResult {
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef {
let lines = self
.inner
.splitlines(options, |x| vm.ctx.new_bytes(x.to_vec()));
Ok(vm.ctx.new_list(lines))
vm.ctx.new_list(lines)
}
#[pymethod(name = "zfill")]

View File

@@ -570,11 +570,8 @@ impl PyInt {
}
#[pymethod(name = "as_integer_ratio")]
fn as_integer_ratio(&self, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.new_tuple(vec![
vm.ctx.new_bigint(&self.value),
vm.ctx.new_bigint(&BigInt::one()),
]))
fn as_integer_ratio(&self, vm: &VirtualMachine) -> (PyObjectRef, BigInt) {
(vm.ctx.new_bigint(&self.value), BigInt::one())
}
#[pymethod]

View File

@@ -117,13 +117,13 @@ impl PyList {
}
#[pymethod(name = "__iadd__")]
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if let Ok(new_elements) = vm.extract_elements(&other) {
let mut e = new_elements;
zelf.borrow_value_mut().append(&mut e);
Ok(zelf.into_object())
zelf.into_object()
} else {
Ok(vm.ctx.not_implemented())
vm.ctx.not_implemented()
}
}

View File

@@ -320,8 +320,8 @@ mod decl {
}
#[pyfunction]
fn globals(vm: &VirtualMachine) -> PyResult<PyDictRef> {
Ok(vm.current_globals().clone())
fn globals(vm: &VirtualMachine) -> PyDictRef {
vm.current_globals().clone()
}
#[pyfunction]

View File

@@ -51,12 +51,7 @@ impl PyModule {
}
#[pymethod(magic)]
fn init(
zelf: PyRef<Self>,
name: PyStrRef,
doc: OptionalOption<PyStrRef>,
vm: &VirtualMachine,
) -> PyResult<()> {
fn init(zelf: PyRef<Self>, name: PyStrRef, doc: OptionalOption<PyStrRef>, vm: &VirtualMachine) {
debug_assert!(crate::pyobject::TypeProtocol::class(zelf.as_object())
.slots
.flags
@@ -67,7 +62,6 @@ impl PyModule {
name.into_object(),
doc.flatten().into_pyobject(vm),
);
Ok(())
}
fn name(zelf: PyRef<Self>, vm: &VirtualMachine) -> Option<String> {

View File

@@ -172,8 +172,8 @@ impl PyBaseObject {
}
#[pyclassmethod(magic)]
fn subclasshook(_args: FuncArgs, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.not_implemented())
fn subclasshook(_args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.not_implemented()
}
#[pyclassmethod(magic)]

View File

@@ -572,8 +572,8 @@ impl PyStr {
}
#[pymethod(name = "__rmod__")]
fn rmod(&self, _values: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.not_implemented())
fn rmod(&self, _values: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.not_implemented()
}
#[pymethod]

View File

@@ -41,32 +41,24 @@ mod decl {
/// Compute an Adler-32 checksum of data.
#[pyfunction]
fn adler32(data: PyBytesRef, begin_state: OptionalArg<i32>, vm: &VirtualMachine) -> PyResult {
fn adler32(data: PyBytesRef, begin_state: OptionalArg<i32>) -> u32 {
let data = data.borrow_value();
let begin_state = begin_state.unwrap_or(1);
let mut hasher = Adler32::from_value(begin_state as u32);
hasher.update_buffer(data);
let checksum: u32 = hasher.hash();
Ok(vm.ctx.new_int(checksum))
hasher.hash()
}
/// Compute a CRC-32 checksum of data.
#[pyfunction]
fn crc32(data: PyBytesRef, begin_state: OptionalArg<i32>, vm: &VirtualMachine) -> PyResult {
fn crc32(data: PyBytesRef, begin_state: OptionalArg<i32>) -> u32 {
let data = data.borrow_value();
let begin_state = begin_state.unwrap_or(0);
let mut hasher = Crc32::new_with_initial(begin_state as u32);
hasher.update(data);
let checksum: u32 = hasher.finalize();
Ok(vm.ctx.new_int(checksum))
hasher.finalize()
}
/// Returns a bytes object containing compressed data.