Skip to content

Commit e2af440

Browse files
committed
Add case where exception dict is empty or missing
1 parent d51593d commit e2af440

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

vm/src/exceptions.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use self::types::{PyBaseException, PyBaseExceptionRef};
22
use crate::common::lock::PyRwLock;
33
use crate::{
44
builtins::{
5-
traceback::PyTracebackRef, PyDictRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType,
6-
PyTypeRef,
5+
traceback::PyTracebackRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
76
},
87
class::{PyClassImpl, StaticType},
98
convert::{ToPyException, ToPyObject},
@@ -522,11 +521,12 @@ impl PyBaseException {
522521
}
523522

524523
#[pymethod(magic)]
525-
fn reduce(
526-
zelf: PyRef<Self>,
527-
_vm: &VirtualMachine,
528-
) -> (PyTypeRef, PyTupleRef, Option<PyDictRef>) {
529-
(zelf.class().clone(), zelf.args(), zelf.as_object().dict())
524+
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyTupleRef {
525+
if let Some(dict) = zelf.as_object().dict().filter(|x| !x.is_empty()) {
526+
return vm.new_tuple((zelf.class().clone(), zelf.args(), dict));
527+
} else {
528+
return vm.new_tuple((zelf.class().clone(), zelf.args()));
529+
}
530530
}
531531
}
532532

0 commit comments

Comments
 (0)