mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add some utility methods to function::Args and PyBaseException
This commit is contained in:
2 files changed
+9
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in new issue
Block a user