Skip to content

Commit d516afb

Browse files
committed
Add BaseException.__reduce__
1 parent 372ed7f commit d516afb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

vm/src/exceptions.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use self::types::{PyBaseException, PyBaseExceptionRef};
22
use crate::common::lock::PyRwLock;
33
use crate::{
44
builtins::{
5-
traceback::PyTracebackRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
5+
traceback::PyTracebackRef, PyDictRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType,
6+
PyTypeRef,
67
},
78
class::{PyClassImpl, StaticType},
89
convert::{ToPyException, ToPyObject},
@@ -519,6 +520,18 @@ impl PyBaseException {
519520
let cls = zelf.class();
520521
format!("{}({})", cls.name(), repr_args.iter().format(", "))
521522
}
523+
524+
#[pymethod(magic)]
525+
fn reduce(
526+
zelf: PyRef<Self>,
527+
_vm: &VirtualMachine,
528+
) -> (PyTypeRef, PyTupleRef, Option<PyDictRef>) {
529+
(
530+
zelf.class().clone(),
531+
zelf.args().clone(),
532+
zelf.as_object().dict(),
533+
)
534+
}
522535
}
523536

524537
impl ExceptionZoo {

0 commit comments

Comments
 (0)