From cb2a994b46145ef7d40e67178f9634d7e72a7065 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 11 Oct 2019 00:50:40 +0900 Subject: [PATCH] Result -> PyResult --- vm/src/function.rs | 2 +- vm/src/obj/objbytearray.rs | 4 ++-- vm/src/obj/objbyteinner.rs | 2 +- vm/src/obj/objsequence.rs | 8 ++------ vm/src/obj/objstr.rs | 2 +- vm/src/stdlib/itertools.rs | 5 +---- vm/src/vm.rs | 2 +- wasm/lib/src/browser_module.rs | 2 +- wasm/lib/src/wasm_builtins.rs | 4 ++-- 9 files changed, 12 insertions(+), 19 deletions(-) diff --git a/vm/src/function.rs b/vm/src/function.rs index 3dcc49a95..8630b28d9 100644 --- a/vm/src/function.rs +++ b/vm/src/function.rs @@ -100,7 +100,7 @@ impl PyFuncArgs { key: &str, ty: PyClassRef, vm: &VirtualMachine, - ) -> Result, PyObjectRef> { + ) -> PyResult> { match self.get_optional_kwarg(key) { Some(kwarg) => { if isinstance(&kwarg, &ty) { diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index 68bfbd3f7..ac31571be 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -473,7 +473,7 @@ impl PyByteArrayRef { } #[pymethod(name = "append")] - fn append(self, x: PyIntRef, vm: &VirtualMachine) -> Result<(), PyObjectRef> { + fn append(self, x: PyIntRef, vm: &VirtualMachine) -> PyResult<()> { self.inner .borrow_mut() .elements @@ -482,7 +482,7 @@ impl PyByteArrayRef { } #[pymethod(name = "extend")] - fn extend(self, iterable_of_ints: PyIterable, vm: &VirtualMachine) -> Result<(), PyObjectRef> { + fn extend(self, iterable_of_ints: PyIterable, vm: &VirtualMachine) -> PyResult<()> { let mut inner = self.inner.borrow_mut(); for x in iterable_of_ints.iter(vm)? { diff --git a/vm/src/obj/objbyteinner.rs b/vm/src/obj/objbyteinner.rs index e402bed31..fc63f15c8 100644 --- a/vm/src/obj/objbyteinner.rs +++ b/vm/src/obj/objbyteinner.rs @@ -1161,7 +1161,7 @@ pub fn try_as_byte(obj: &PyObjectRef) -> Option> { } pub trait ByteOr: ToPrimitive { - fn byte_or(&self, vm: &VirtualMachine) -> Result { + fn byte_or(&self, vm: &VirtualMachine) -> PyResult { match self.to_u8() { Some(value) => Ok(value), None => Err(vm.new_value_error("byte must be in range(0, 256)".to_string())), diff --git a/vm/src/obj/objsequence.rs b/vm/src/obj/objsequence.rs index accb284c2..d8b3800eb 100644 --- a/vm/src/obj/objsequence.rs +++ b/vm/src/obj/objsequence.rs @@ -65,11 +65,7 @@ pub trait PySliceableSequence { start..stop } - fn get_slice_items( - &self, - vm: &VirtualMachine, - slice: &PyObjectRef, - ) -> Result + fn get_slice_items(&self, vm: &VirtualMachine, slice: &PyObjectRef) -> PyResult where Self: Sized, { @@ -410,7 +406,7 @@ pub fn get_mut_elements<'a>(obj: &'a PyObjectRef) -> impl DerefMut, vm: &VirtualMachine, -) -> Result, PyObjectRef> { +) -> PyResult> { if let OptionalArg::Present(value) = arg { match_class!(match value { i @ PyInt => Ok(Some(i.as_bigint().clone())), diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 1bf34f059..79872a6bf 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -1260,7 +1260,7 @@ fn do_cformat_specifier( vm: &VirtualMachine, format_spec: &mut CFormatSpec, obj: PyObjectRef, -) -> Result { +) -> PyResult { use CNumberType::*; // do the formatting by type let format_type = &format_spec.format_type; diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 48243135e..f83dfe123 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -640,10 +640,7 @@ struct PyItertoolsTeeData { } impl PyItertoolsTeeData { - fn new( - iterable: PyObjectRef, - vm: &VirtualMachine, - ) -> Result, PyObjectRef> { + fn new(iterable: PyObjectRef, vm: &VirtualMachine) -> PyResult> { Ok(Rc::new(PyItertoolsTeeData { iterable: get_iter(vm, &iterable)?, values: RefCell::new(vec![]), diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 1bb54c414..2871329f6 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -467,7 +467,7 @@ impl VirtualMachine { TryFromObject::try_from_object(self, str) } - pub fn to_pystr<'a, T: Into<&'a PyObjectRef>>(&'a self, obj: T) -> Result { + pub fn to_pystr<'a, T: Into<&'a PyObjectRef>>(&'a self, obj: T) -> PyResult { let py_str_obj = self.to_str(obj.into())?; Ok(py_str_obj.as_str().to_owned()) } diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index 9bdf39803..86c0d93f9 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -24,7 +24,7 @@ enum FetchResponseFormat { } impl FetchResponseFormat { - fn from_str(vm: &VirtualMachine, s: &str) -> Result { + fn from_str(vm: &VirtualMachine, s: &str) -> PyResult { match s { "json" => Ok(FetchResponseFormat::Json), "text" => Ok(FetchResponseFormat::Text), diff --git a/wasm/lib/src/wasm_builtins.rs b/wasm/lib/src/wasm_builtins.rs index ada0c83f5..7fc6f6534 100644 --- a/wasm/lib/src/wasm_builtins.rs +++ b/wasm/lib/src/wasm_builtins.rs @@ -9,14 +9,14 @@ use web_sys::{self, console}; use rustpython_vm::function::PyFuncArgs; use rustpython_vm::obj::{objstr, objtype}; -use rustpython_vm::pyobject::{IdProtocol, PyObjectRef, PyResult, TypeProtocol}; +use rustpython_vm::pyobject::{IdProtocol, PyResult, TypeProtocol}; use rustpython_vm::VirtualMachine; pub(crate) fn window() -> web_sys::Window { web_sys::window().expect("Window to be available") } -pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> Result { +pub fn format_print_args(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { // Handle 'sep' kwarg: let sep_arg = args .get_optional_kwarg("sep")