From cb9c9ec4cf62ca2572b03cfe14da22db05c93295 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:49:57 -0500 Subject: [PATCH] Add some utility methods to function::Args and PyBaseException --- vm/src/exceptions.rs | 6 +++++- vm/src/function.rs | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index e27f14f18..d22c882a7 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -72,6 +72,10 @@ impl PyBaseException { Ok(()) } + pub fn get_arg(&self, idx: usize) -> Option { + self.args.read().borrow_value().get(idx).cloned() + } + #[pyproperty] pub fn args(&self) -> PyTupleRef { self.args.read().clone() @@ -641,7 +645,7 @@ fn none_getter(_obj: PyObjectRef, vm: &VirtualMachine) -> PyNoneRef { } fn make_arg_getter(idx: usize) -> impl Fn(PyBaseExceptionRef) -> Option { - move |exc| exc.args.read().borrow_value().get(idx).cloned() + move |exc| exc.get_arg(idx) } fn key_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef { diff --git a/vm/src/function.rs b/vm/src/function.rs index 593242752..5decc19a8 100644 --- a/vm/src/function.rs +++ b/vm/src/function.rs @@ -352,6 +352,10 @@ impl Args { pub fn into_vec(self) -> Vec { self.0 } + + pub fn iter(&self) -> std::slice::Iter { + self.0.iter() + } } impl From> for Args {