Skip to content

Commit 0f0de02

Browse files
committed
Implement __sub__/__rsub__.
1 parent 0199137 commit 0f0de02

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

vm/src/vm.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,22 @@ impl VirtualMachine {
438438

439439
pub fn _sub(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
440440
// Try __sub__, next __rsub__, next, give up
441-
self.call_method(&a, "__sub__", vec![b])
442-
/*
443-
if a.has_attr("__sub__") {
444-
self.call_method(&a, "__sub__", vec![b])
445-
} else if b.has_attr("__rsub__") {
446-
self.call_method(&b, "__rsub__", vec![a])
441+
if let Ok(method) = self.get_method(a.clone(), "__sub__") {
442+
self.invoke(
443+
method,
444+
PyFuncArgs {
445+
args: vec![b],
446+
kwargs: vec![],
447+
},
448+
)
449+
} else if let Ok(method) = self.get_method(b.clone(), "__rsub__") {
450+
self.invoke(
451+
method,
452+
PyFuncArgs {
453+
args: vec![a],
454+
kwargs: vec![],
455+
},
456+
)
447457
} else {
448458
// Cannot sub a and b
449459
let a_type_name = objtype::get_type_name(&a.typ());
@@ -453,7 +463,6 @@ impl VirtualMachine {
453463
a_type_name, b_type_name
454464
)))
455465
}
456-
*/
457466
}
458467

459468
pub fn _add(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {

0 commit comments

Comments
 (0)