From f840bdcd7fa8b47434e0470f617d8b488c9dccd3 Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Thu, 4 Apr 2019 14:47:44 +0100 Subject: [PATCH] Generalise set_attr. --- vm/src/vm.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 2fad29124..1649d4efc 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -568,13 +568,16 @@ impl VirtualMachine { self.call_method(&obj, "__getattribute__", vec![attr_name.into_object()]) } - pub fn set_attr( - &self, - obj: &PyObjectRef, - attr_name: PyObjectRef, - attr_value: PyObjectRef, - ) -> PyResult { - self.call_method(&obj, "__setattr__", vec![attr_name, attr_value]) + pub fn set_attr(&self, obj: &PyObjectRef, attr_name: K, attr_value: PyObjectRef) -> PyResult + where + K: TryIntoRef, + { + let attr_name = attr_name.try_into_ref(self)?; + self.call_method( + obj, + "__setattr__", + vec![attr_name.into_object(), attr_value], + ) } pub fn del_attr(&self, obj: &PyObjectRef, attr_name: PyObjectRef) -> PyResult<()> {