Skip to content

Commit f9860d0

Browse files
committed
Moved and to use new method
1 parent 15c6328 commit f9860d0

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
@@ -558,50 +558,7 @@ impl VirtualMachine {
558558
}
559559

560560
pub fn _and(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
561-
// 1. Try __and__, next __rand__, next, give up
562-
if let Ok(method) = self.get_method(a.clone(), "__and__") {
563-
match self.invoke(
564-
method,
565-
PyFuncArgs {
566-
args: vec![b.clone()],
567-
kwargs: vec![],
568-
},
569-
) {
570-
Ok(value) => return Ok(value),
571-
Err(err) => {
572-
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
573-
return Err(err);
574-
}
575-
}
576-
}
577-
}
578-
579-
// 2. try __rand__
580-
if let Ok(method) = self.get_method(b.clone(), "__rand__") {
581-
match self.invoke(
582-
method,
583-
PyFuncArgs {
584-
args: vec![a.clone()],
585-
kwargs: vec![],
586-
},
587-
) {
588-
Ok(value) => return Ok(value),
589-
Err(err) => {
590-
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
591-
return Err(err);
592-
}
593-
}
594-
}
595-
}
596-
597-
// 3. It all failed :(
598-
// Cannot and a and b
599-
let a_type_name = objtype::get_type_name(&a.typ());
600-
let b_type_name = objtype::get_type_name(&b.typ());
601-
Err(self.new_type_error(format!(
602-
"Unsupported operand types for '&': '{}' and '{}'",
603-
a_type_name, b_type_name
604-
)))
561+
self.call_or_unsupported(a, b, "__and__", "__rand__", "&")
605562
}
606563

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

0 commit comments

Comments
 (0)