Skip to content

Commit d15da72

Browse files
committed
Fix return types
1 parent 1c12a80 commit d15da72

File tree

9 files changed

+23
-41
lines changed

9 files changed

+23
-41
lines changed

vm/src/builtins/bytearray.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,11 @@ impl PyByteArray {
545545
}
546546

547547
#[pymethod(name = "splitlines")]
548-
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyResult {
548+
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef {
549549
let lines = self
550550
.borrow_value()
551551
.splitlines(options, |x| vm.ctx.new_bytearray(x.to_vec()));
552-
Ok(vm.ctx.new_list(lines))
552+
vm.ctx.new_list(lines)
553553
}
554554

555555
#[pymethod(name = "zfill")]
@@ -607,9 +607,8 @@ impl PyByteArray {
607607
}
608608

609609
#[pymethod(name = "reverse")]
610-
fn reverse(&self) -> PyResult<()> {
610+
fn reverse(&self) {
611611
self.borrow_value_mut().elements.reverse();
612-
Ok(())
613612
}
614613

615614
#[pymethod]

vm/src/builtins/bytes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ impl PyBytes {
118118
}
119119

120120
#[pymethod(name = "__sizeof__")]
121-
fn sizeof(&self) -> PyResult<usize> {
122-
Ok(size_of::<Self>() + self.inner.elements.len() * size_of::<u8>())
121+
fn sizeof(&self) -> usize {
122+
size_of::<Self>() + self.inner.elements.len() * size_of::<u8>()
123123
}
124124

125125
#[pymethod(name = "__add__")]
@@ -387,11 +387,11 @@ impl PyBytes {
387387
}
388388

389389
#[pymethod(name = "splitlines")]
390-
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyResult {
390+
fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef {
391391
let lines = self
392392
.inner
393393
.splitlines(options, |x| vm.ctx.new_bytes(x.to_vec()));
394-
Ok(vm.ctx.new_list(lines))
394+
vm.ctx.new_list(lines)
395395
}
396396

397397
#[pymethod(name = "zfill")]

vm/src/builtins/int.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,8 @@ impl PyInt {
570570
}
571571

572572
#[pymethod(name = "as_integer_ratio")]
573-
fn as_integer_ratio(&self, vm: &VirtualMachine) -> PyResult {
574-
Ok(vm.ctx.new_tuple(vec![
575-
vm.ctx.new_bigint(&self.value),
576-
vm.ctx.new_bigint(&BigInt::one()),
577-
]))
573+
fn as_integer_ratio(&self, vm: &VirtualMachine) -> (PyObjectRef, BigInt) {
574+
(vm.ctx.new_bigint(&self.value), BigInt::one())
578575
}
579576

580577
#[pymethod]

vm/src/builtins/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ impl PyList {
117117
}
118118

119119
#[pymethod(name = "__iadd__")]
120-
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
120+
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
121121
if let Ok(new_elements) = vm.extract_elements(&other) {
122122
let mut e = new_elements;
123123
zelf.borrow_value_mut().append(&mut e);
124-
Ok(zelf.into_object())
124+
zelf.into_object()
125125
} else {
126-
Ok(vm.ctx.not_implemented())
126+
vm.ctx.not_implemented()
127127
}
128128
}
129129

vm/src/builtins/make_module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ mod decl {
320320
}
321321

322322
#[pyfunction]
323-
fn globals(vm: &VirtualMachine) -> PyResult<PyDictRef> {
324-
Ok(vm.current_globals().clone())
323+
fn globals(vm: &VirtualMachine) -> PyDictRef {
324+
vm.current_globals().clone()
325325
}
326326

327327
#[pyfunction]

vm/src/builtins/module.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ impl PyModule {
5151
}
5252

5353
#[pymethod(magic)]
54-
fn init(
55-
zelf: PyRef<Self>,
56-
name: PyStrRef,
57-
doc: OptionalOption<PyStrRef>,
58-
vm: &VirtualMachine,
59-
) -> PyResult<()> {
54+
fn init(zelf: PyRef<Self>, name: PyStrRef, doc: OptionalOption<PyStrRef>, vm: &VirtualMachine) {
6055
debug_assert!(crate::pyobject::TypeProtocol::class(zelf.as_object())
6156
.slots
6257
.flags
@@ -67,7 +62,6 @@ impl PyModule {
6762
name.into_object(),
6863
doc.flatten().into_pyobject(vm),
6964
);
70-
Ok(())
7165
}
7266

7367
fn name(zelf: PyRef<Self>, vm: &VirtualMachine) -> Option<String> {

vm/src/builtins/object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ impl PyBaseObject {
172172
}
173173

174174
#[pyclassmethod(magic)]
175-
fn subclasshook(_args: FuncArgs, vm: &VirtualMachine) -> PyResult {
176-
Ok(vm.ctx.not_implemented())
175+
fn subclasshook(_args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef {
176+
vm.ctx.not_implemented()
177177
}
178178

179179
#[pyclassmethod(magic)]

vm/src/builtins/pystr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ impl PyStr {
572572
}
573573

574574
#[pymethod(name = "__rmod__")]
575-
fn rmod(&self, _values: PyObjectRef, vm: &VirtualMachine) -> PyResult {
576-
Ok(vm.ctx.not_implemented())
575+
fn rmod(&self, _values: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
576+
vm.ctx.not_implemented()
577577
}
578578

579579
#[pymethod]

vm/src/stdlib/zlib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,24 @@ mod decl {
4141

4242
/// Compute an Adler-32 checksum of data.
4343
#[pyfunction]
44-
fn adler32(data: PyBytesRef, begin_state: OptionalArg<i32>, vm: &VirtualMachine) -> PyResult {
44+
fn adler32(data: PyBytesRef, begin_state: OptionalArg<i32>) -> u32 {
4545
let data = data.borrow_value();
46-
4746
let begin_state = begin_state.unwrap_or(1);
4847

4948
let mut hasher = Adler32::from_value(begin_state as u32);
5049
hasher.update_buffer(data);
51-
52-
let checksum: u32 = hasher.hash();
53-
54-
Ok(vm.ctx.new_int(checksum))
50+
hasher.hash()
5551
}
5652

5753
/// Compute a CRC-32 checksum of data.
5854
#[pyfunction]
59-
fn crc32(data: PyBytesRef, begin_state: OptionalArg<i32>, vm: &VirtualMachine) -> PyResult {
55+
fn crc32(data: PyBytesRef, begin_state: OptionalArg<i32>) -> u32 {
6056
let data = data.borrow_value();
61-
6257
let begin_state = begin_state.unwrap_or(0);
6358

6459
let mut hasher = Crc32::new_with_initial(begin_state as u32);
6560
hasher.update(data);
66-
67-
let checksum: u32 = hasher.finalize();
68-
69-
Ok(vm.ctx.new_int(checksum))
61+
hasher.finalize()
7062
}
7163

7264
/// Returns a bytes object containing compressed data.

0 commit comments

Comments
 (0)