Add some utility methods to function::Args and PyBaseException

This commit is contained in:
Noah committed 2020-10-16 20:49:57 -05:00
1 parent 79d5872942
commit cb9c9ec4cf
2 files changed
+9 -1

No files matched your search

+5 -1
View File
@@ -72,6 +72,10 @@ impl PyBaseException {
Ok(())
}
pub fn get_arg(&self, idx: usize) -> Option<PyObjectRef> {
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<PyObjectRef> {
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 {
+4
View File
@@ -352,6 +352,10 @@ impl<T> Args<T> {
pub fn into_vec(self) -> Vec<T> {
self.0
}
pub fn iter(&self) -> std::slice::Iter<T> {
self.0.iter()
}
}
impl<T> From<Vec<T>> for Args<T> {