Skip to content

Commit 181dff8

Browse files
committed
Fix setting attributes on errors
1 parent 777542f commit 181dff8

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

vm/src/pyobject.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ pub trait PyValue: fmt::Debug + Sized + 'static {
10851085
fn class(vm: &VirtualMachine) -> PyClassRef;
10861086

10871087
fn into_ref(self, vm: &VirtualMachine) -> PyRef<Self> {
1088-
self.into_ref_with_type_unchecked(Self::class(vm))
1088+
self.into_ref_with_type_unchecked(Self::class(vm), None)
10891089
}
10901090

10911091
fn into_ref_with_type(self, vm: &VirtualMachine, cls: PyClassRef) -> PyResult<PyRef<Self>> {
@@ -1104,8 +1104,8 @@ pub trait PyValue: fmt::Debug + Sized + 'static {
11041104
}
11051105
}
11061106

1107-
fn into_ref_with_type_unchecked(self, cls: PyClassRef) -> PyRef<Self> {
1108-
PyRef::new_ref_unchecked(PyObject::new(self, cls, None))
1107+
fn into_ref_with_type_unchecked(self, cls: PyClassRef, dict: Option<PyDictRef>) -> PyRef<Self> {
1108+
PyRef::new_ref_unchecked(PyObject::new(self, cls, dict))
11091109
}
11101110
}
11111111

vm/src/vm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ impl VirtualMachine {
343343
) -> PyBaseExceptionRef {
344344
// TODO: add repr of args into logging?
345345
vm_trace!("New exception created: {}", exc_type.name);
346-
PyBaseException::new(args, self).into_ref_with_type_unchecked(exc_type)
346+
PyBaseException::new(args, self)
347+
.into_ref_with_type_unchecked(exc_type, Some(self.ctx.new_dict()))
347348
}
348349

349350
/// Instantiate an exception with no arguments.

0 commit comments

Comments
 (0)