From 3ccccfcabe117575ce430685d19f660394f3b51d Mon Sep 17 00:00:00 2001 From: CHOUMnote Date: Sat, 21 May 2022 16:34:34 +0900 Subject: [PATCH] add __str__ in PyWeakProxy file : test_deque.py method : test_weakref() error occurred because the return value of str() was different so add __str__() in weakproxy Signed-off-by: CHOUMnote --- vm/src/builtins/weakproxy.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vm/src/builtins/weakproxy.rs b/vm/src/builtins/weakproxy.rs index 7bb80bc45..2b5c058c5 100644 --- a/vm/src/builtins/weakproxy.rs +++ b/vm/src/builtins/weakproxy.rs @@ -70,6 +70,16 @@ impl PyWeakProxy { })?; obj.get_attr(attr_name, vm) } + #[pymethod(magic)] + fn str(&self, vm: &VirtualMachine) -> PyResult { + match self.weak.upgrade() { + Some(obj) => obj.str(vm), + None => Err(vm.new_exception_msg( + vm.ctx.exceptions.reference_error.clone(), + "weakly-referenced object no longer exists".to_owned(), + )), + } + } } impl SetAttr for PyWeakProxy {