Add BaseException.__reduce__

This commit is contained in:
Padraic Fanning
2022-04-27 20:33:26 -04:00
parent 372ed7f737
commit d516afb5f6

View File

@@ -2,7 +2,8 @@ use self::types::{PyBaseException, PyBaseExceptionRef};
use crate::common::lock::PyRwLock;
use crate::{
builtins::{
traceback::PyTracebackRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
traceback::PyTracebackRef, PyDictRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType,
PyTypeRef,
},
class::{PyClassImpl, StaticType},
convert::{ToPyException, ToPyObject},
@@ -519,6 +520,18 @@ impl PyBaseException {
let cls = zelf.class();
format!("{}({})", cls.name(), repr_args.iter().format(", "))
}
#[pymethod(magic)]
fn reduce(
zelf: PyRef<Self>,
_vm: &VirtualMachine,
) -> (PyTypeRef, PyTupleRef, Option<PyDictRef>) {
(
zelf.class().clone(),
zelf.args().clone(),
zelf.as_object().dict(),
)
}
}
impl ExceptionZoo {