From d516afb5f6bb994f699d212927a8cea085be79b5 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Wed, 27 Apr 2022 20:33:26 -0400 Subject: [PATCH] Add BaseException.__reduce__ --- vm/src/exceptions.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 272251591..226c0d942 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -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, + _vm: &VirtualMachine, + ) -> (PyTypeRef, PyTupleRef, Option) { + ( + zelf.class().clone(), + zelf.args().clone(), + zelf.as_object().dict(), + ) + } } impl ExceptionZoo {