From e2af440af1b0735426432d01c9276ccf7fe46181 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Wed, 27 Apr 2022 22:50:19 -0400 Subject: [PATCH] Add case where exception dict is empty or missing --- vm/src/exceptions.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index be17ffbd6..6fe2da677 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -2,8 +2,7 @@ use self::types::{PyBaseException, PyBaseExceptionRef}; use crate::common::lock::PyRwLock; use crate::{ builtins::{ - traceback::PyTracebackRef, PyDictRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, - PyTypeRef, + traceback::PyTracebackRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, }, class::{PyClassImpl, StaticType}, convert::{ToPyException, ToPyObject}, @@ -522,11 +521,12 @@ impl PyBaseException { } #[pymethod(magic)] - fn reduce( - zelf: PyRef, - _vm: &VirtualMachine, - ) -> (PyTypeRef, PyTupleRef, Option) { - (zelf.class().clone(), zelf.args(), zelf.as_object().dict()) + fn reduce(zelf: PyRef, vm: &VirtualMachine) -> PyTupleRef { + if let Some(dict) = zelf.as_object().dict().filter(|x| !x.is_empty()) { + return vm.new_tuple((zelf.class().clone(), zelf.args(), dict)); + } else { + return vm.new_tuple((zelf.class().clone(), zelf.args())); + } } }