Skip to content

Commit cb2a994

Browse files
committed
Result<T, PyObjectRef> -> PyResult<T>
1 parent 8bce893 commit cb2a994

File tree

9 files changed

+12
-19
lines changed

9 files changed

+12
-19
lines changed

vm/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl PyFuncArgs {
100100
key: &str,
101101
ty: PyClassRef,
102102
vm: &VirtualMachine,
103-
) -> Result<Option<PyObjectRef>, PyObjectRef> {
103+
) -> PyResult<Option<PyObjectRef>> {
104104
match self.get_optional_kwarg(key) {
105105
Some(kwarg) => {
106106
if isinstance(&kwarg, &ty) {

vm/src/obj/objbytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl PyByteArrayRef {
473473
}
474474

475475
#[pymethod(name = "append")]
476-
fn append(self, x: PyIntRef, vm: &VirtualMachine) -> Result<(), PyObjectRef> {
476+
fn append(self, x: PyIntRef, vm: &VirtualMachine) -> PyResult<()> {
477477
self.inner
478478
.borrow_mut()
479479
.elements
@@ -482,7 +482,7 @@ impl PyByteArrayRef {
482482
}
483483

484484
#[pymethod(name = "extend")]
485-
fn extend(self, iterable_of_ints: PyIterable, vm: &VirtualMachine) -> Result<(), PyObjectRef> {
485+
fn extend(self, iterable_of_ints: PyIterable, vm: &VirtualMachine) -> PyResult<()> {
486486
let mut inner = self.inner.borrow_mut();
487487

488488
for x in iterable_of_ints.iter(vm)? {

vm/src/obj/objbyteinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ pub fn try_as_byte(obj: &PyObjectRef) -> Option<Vec<u8>> {
11611161
}
11621162

11631163
pub trait ByteOr: ToPrimitive {
1164-
fn byte_or(&self, vm: &VirtualMachine) -> Result<u8, PyObjectRef> {
1164+
fn byte_or(&self, vm: &VirtualMachine) -> PyResult<u8> {
11651165
match self.to_u8() {
11661166
Some(value) => Ok(value),
11671167
None => Err(vm.new_value_error("byte must be in range(0, 256)".to_string())),

vm/src/obj/objsequence.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ pub trait PySliceableSequence {
6565
start..stop
6666
}
6767

68-
fn get_slice_items(
69-
&self,
70-
vm: &VirtualMachine,
71-
slice: &PyObjectRef,
72-
) -> Result<Self::Sliced, PyObjectRef>
68+
fn get_slice_items(&self, vm: &VirtualMachine, slice: &PyObjectRef) -> PyResult<Self::Sliced>
7369
where
7470
Self: Sized,
7571
{
@@ -410,7 +406,7 @@ pub fn get_mut_elements<'a>(obj: &'a PyObjectRef) -> impl DerefMut<Target = Vec<
410406
pub fn is_valid_slice_arg(
411407
arg: OptionalArg<PyObjectRef>,
412408
vm: &VirtualMachine,
413-
) -> Result<Option<BigInt>, PyObjectRef> {
409+
) -> PyResult<Option<BigInt>> {
414410
if let OptionalArg::Present(value) = arg {
415411
match_class!(match value {
416412
i @ PyInt => Ok(Some(i.as_bigint().clone())),

vm/src/obj/objstr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ fn do_cformat_specifier(
12601260
vm: &VirtualMachine,
12611261
format_spec: &mut CFormatSpec,
12621262
obj: PyObjectRef,
1263-
) -> Result<String, PyObjectRef> {
1263+
) -> PyResult<String> {
12641264
use CNumberType::*;
12651265
// do the formatting by type
12661266
let format_type = &format_spec.format_type;

vm/src/stdlib/itertools.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,7 @@ struct PyItertoolsTeeData {
640640
}
641641

642642
impl PyItertoolsTeeData {
643-
fn new(
644-
iterable: PyObjectRef,
645-
vm: &VirtualMachine,
646-
) -> Result<Rc<PyItertoolsTeeData>, PyObjectRef> {
643+
fn new(iterable: PyObjectRef, vm: &VirtualMachine) -> PyResult<Rc<PyItertoolsTeeData>> {
647644
Ok(Rc::new(PyItertoolsTeeData {
648645
iterable: get_iter(vm, &iterable)?,
649646
values: RefCell::new(vec![]),

vm/src/vm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl VirtualMachine {
467467
TryFromObject::try_from_object(self, str)
468468
}
469469

470-
pub fn to_pystr<'a, T: Into<&'a PyObjectRef>>(&'a self, obj: T) -> Result<String, PyObjectRef> {
470+
pub fn to_pystr<'a, T: Into<&'a PyObjectRef>>(&'a self, obj: T) -> PyResult<String> {
471471
let py_str_obj = self.to_str(obj.into())?;
472472
Ok(py_str_obj.as_str().to_owned())
473473
}

wasm/lib/src/browser_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum FetchResponseFormat {
2424
}
2525

2626
impl FetchResponseFormat {
27-
fn from_str(vm: &VirtualMachine, s: &str) -> Result<Self, PyObjectRef> {
27+
fn from_str(vm: &VirtualMachine, s: &str) -> PyResult<Self> {
2828
match s {
2929
"json" => Ok(FetchResponseFormat::Json),
3030
"text" => Ok(FetchResponseFormat::Text),

wasm/lib/src/wasm_builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use web_sys::{self, console};
99

1010
use rustpython_vm::function::PyFuncArgs;
1111
use rustpython_vm::obj::{objstr, objtype};
12-
use rustpython_vm::pyobject::{IdProtocol, PyObjectRef, PyResult, TypeProtocol};
12+
use rustpython_vm::pyobject::{IdProtocol, PyResult, TypeProtocol};
1313
use rustpython_vm::VirtualMachine;
1414

1515
pub(crate) fn window() -> web_sys::Window {
1616
web_sys::window().expect("Window to be available")
1717
}
1818

19-
pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> Result<String, PyObjectRef> {
19+
pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult<String> {
2020
// Handle 'sep' kwarg:
2121
let sep_arg = args
2222
.get_optional_kwarg("sep")

0 commit comments

Comments
 (0)