From 7defbe927be384518907a9aacabdbd7209a7d6d2 Mon Sep 17 00:00:00 2001 From: Hyunji Kim Date: Sun, 29 Sep 2019 15:34:25 +0900 Subject: [PATCH 1/2] fix error message for __call__ for non-callable objects --- vm/src/vm.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 71e754b96..fb99b285c 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -604,9 +604,14 @@ impl VirtualMachine { } else if let Some(PyBuiltinFunction { ref value }) = func_ref.payload() { value(self, args) } else { - // TODO: is it safe to just invoke __call__ otherwise? - vm_trace!("invoke __call__ for: {:?}", &func_ref.payload); - self.call_method(&func_ref, "__call__", args) + if self.is_callable(&func_ref) { + self.call_method(&func_ref, "__call__", args) + } else { + Err(self.new_type_error(format!( + "'{}' object is not callable", + func_ref.class().name + ))) + } } } From 83a7a4d9ed10b80d60f153e5c0043b811908e3c9 Mon Sep 17 00:00:00 2001 From: Hyunji Kim Date: Sun, 6 Oct 2019 15:58:02 +0900 Subject: [PATCH 2/2] fix clippy lint --- vm/src/vm.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vm/src/vm.rs b/vm/src/vm.rs index fb99b285c..ba854e8c6 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -603,15 +603,13 @@ impl VirtualMachine { self.invoke(&function, args.insert(object.clone())) } else if let Some(PyBuiltinFunction { ref value }) = func_ref.payload() { value(self, args) + } else if self.is_callable(&func_ref) { + self.call_method(&func_ref, "__call__", args) } else { - if self.is_callable(&func_ref) { - self.call_method(&func_ref, "__call__", args) - } else { - Err(self.new_type_error(format!( - "'{}' object is not callable", - func_ref.class().name - ))) - } + Err(self.new_type_error(format!( + "'{}' object is not callable", + func_ref.class().name + ))) } }