Fix setting attributes on errors

This commit is contained in:
coolreader18
2019-12-28 20:19:24 -06:00
parent 777542f7ec
commit 181dff867f
2 changed files with 5 additions and 4 deletions

View File

@@ -1085,7 +1085,7 @@ pub trait PyValue: fmt::Debug + Sized + 'static {
fn class(vm: &VirtualMachine) -> PyClassRef;
fn into_ref(self, vm: &VirtualMachine) -> PyRef<Self> {
self.into_ref_with_type_unchecked(Self::class(vm))
self.into_ref_with_type_unchecked(Self::class(vm), None)
}
fn into_ref_with_type(self, vm: &VirtualMachine, cls: PyClassRef) -> PyResult<PyRef<Self>> {
@@ -1104,8 +1104,8 @@ pub trait PyValue: fmt::Debug + Sized + 'static {
}
}
fn into_ref_with_type_unchecked(self, cls: PyClassRef) -> PyRef<Self> {
PyRef::new_ref_unchecked(PyObject::new(self, cls, None))
fn into_ref_with_type_unchecked(self, cls: PyClassRef, dict: Option<PyDictRef>) -> PyRef<Self> {
PyRef::new_ref_unchecked(PyObject::new(self, cls, dict))
}
}

View File

@@ -343,7 +343,8 @@ impl VirtualMachine {
) -> PyBaseExceptionRef {
// TODO: add repr of args into logging?
vm_trace!("New exception created: {}", exc_type.name);
PyBaseException::new(args, self).into_ref_with_type_unchecked(exc_type)
PyBaseException::new(args, self)
.into_ref_with_type_unchecked(exc_type, Some(self.ctx.new_dict()))
}
/// Instantiate an exception with no arguments.