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 {