Skip to content

Commit 15c6328

Browse files
committed
Moved sub to use new method
1 parent 05d2faa commit 15c6328

File tree

1 file changed

+1
-44
lines changed

1 file changed

+1
-44
lines changed

vm/src/vm.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -526,50 +526,7 @@ impl VirtualMachine {
526526
}
527527

528528
pub fn _sub(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
529-
// 1. Try __sub__, next __rsub__, next, give up
530-
if let Ok(method) = self.get_method(a.clone(), "__sub__") {
531-
match self.invoke(
532-
method,
533-
PyFuncArgs {
534-
args: vec![b.clone()],
535-
kwargs: vec![],
536-
},
537-
) {
538-
Ok(value) => return Ok(value),
539-
Err(err) => {
540-
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
541-
return Err(err);
542-
}
543-
}
544-
}
545-
}
546-
547-
// 2. try __rsub__
548-
if let Ok(method) = self.get_method(b.clone(), "__rsub__") {
549-
match self.invoke(
550-
method,
551-
PyFuncArgs {
552-
args: vec![a.clone()],
553-
kwargs: vec![],
554-
},
555-
) {
556-
Ok(value) => return Ok(value),
557-
Err(err) => {
558-
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
559-
return Err(err);
560-
}
561-
}
562-
}
563-
}
564-
565-
// 3. It all failed :(
566-
// Cannot sub a and b
567-
let a_type_name = objtype::get_type_name(&a.typ());
568-
let b_type_name = objtype::get_type_name(&b.typ());
569-
Err(self.new_type_error(format!(
570-
"Unsupported operand types for '-': '{}' and '{}'",
571-
a_type_name, b_type_name
572-
)))
529+
self.call_or_unsupported(a, b, "__sub__", "__rsub__", "-")
573530
}
574531

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

0 commit comments

Comments
 (0)