diff --git a/vm/src/builtins/weakproxy.rs b/vm/src/builtins/weakproxy.rs index 224b18f45..5ff585a73 100644 --- a/vm/src/builtins/weakproxy.rs +++ b/vm/src/builtins/weakproxy.rs @@ -47,14 +47,14 @@ impl SlotConstructor for PyWeakProxy { impl PyWeakProxy { // TODO: callbacks #[pymethod(magic)] - fn getattr(&self, attr_name: PyObjectRef, vm: &VirtualMachine) -> PyResult { - match self.weak.upgrade() { - Some(obj) => vm.get_attribute(obj, attr_name), - None => Err(vm.new_exception_msg( + fn getattr(&self, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult { + let obj = self.weak.upgrade().ok_or_else(|| { + vm.new_exception_msg( vm.ctx.exceptions.reference_error.clone(), "weakly-referenced object no longer exists".to_owned(), - )), - } + ) + })?; + vm.get_attribute(obj, attr_name) } } diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index d7a588c5d..c0a1283b3 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -626,15 +626,6 @@ impl TryIntoRef for PyRef { } } -impl TryIntoRef for PyObjectRef -where - T: PyValue, -{ - fn try_into_ref(self, vm: &VirtualMachine) -> PyResult> { - TryFromObject::try_from_object(vm, self) - } -} - /// Implemented by any type that can be created from a Python object. /// /// Any type that implements `TryFromObject` is automatically `FromArgs`, and diff --git a/vm/src/stdlib/errno.rs b/vm/src/stdlib/errno.rs index 670018148..2e4b456b1 100644 --- a/vm/src/stdlib/errno.rs +++ b/vm/src/stdlib/errno.rs @@ -7,9 +7,11 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { "errorcode" => errorcode.clone(), }); for (name, code) in ERROR_CODES { - let name = vm.new_pyobj(*name); + let name = vm.ctx.new_str(*name); let code = vm.new_pyobj(*code); - errorcode.set_item(code.clone(), name.clone(), vm).unwrap(); + errorcode + .set_item(code.clone(), name.clone().into(), vm) + .unwrap(); vm.set_attr(&module, name, code).unwrap(); } module