mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Implemented __reduce__ method for the ImportError exception (#4973)
This commit is contained in:
@@ -1182,6 +1182,20 @@ pub(super) mod types {
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn reduce(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
let obj = exc.as_object().to_owned();
|
||||
let mut result: Vec<PyObjectRef> = vec![
|
||||
obj.class().to_owned().into(),
|
||||
vm.new_tuple((exc.get_arg(0).unwrap(),)).into(),
|
||||
];
|
||||
|
||||
if let Some(dict) = obj.dict().filter(|x| !x.is_empty()) {
|
||||
result.push(dict.into());
|
||||
}
|
||||
|
||||
result.into_pytuple(vm)
|
||||
}
|
||||
}
|
||||
|
||||
#[pyexception(name, base = "PyImportError", ctx = "module_not_found_error", impl)]
|
||||
|
||||
Reference in New Issue
Block a user