mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Moved and to use new method
This commit is contained in:
1 parent
15c6328ecd
commit
f9860d083e
1 file changed
+1
-44
+1
-44
@@ -558,50 +558,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn _and(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
|
||||
// 1. Try __and__, next __rand__, next, give up
|
||||
if let Ok(method) = self.get_method(a.clone(), "__and__") {
|
||||
match self.invoke(
|
||||
method,
|
||||
PyFuncArgs {
|
||||
args: vec![b.clone()],
|
||||
kwargs: vec![],
|
||||
},
|
||||
) {
|
||||
Ok(value) => return Ok(value),
|
||||
Err(err) => {
|
||||
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. try __rand__
|
||||
if let Ok(method) = self.get_method(b.clone(), "__rand__") {
|
||||
match self.invoke(
|
||||
method,
|
||||
PyFuncArgs {
|
||||
args: vec![a.clone()],
|
||||
kwargs: vec![],
|
||||
},
|
||||
) {
|
||||
Ok(value) => return Ok(value),
|
||||
Err(err) => {
|
||||
if !objtype::isinstance(&err, &self.ctx.exceptions.not_implemented_error) {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. It all failed :(
|
||||
// Cannot and a and b
|
||||
let a_type_name = objtype::get_type_name(&a.typ());
|
||||
let b_type_name = objtype::get_type_name(&b.typ());
|
||||
Err(self.new_type_error(format!(
|
||||
"Unsupported operand types for '&': '{}' and '{}'",
|
||||
a_type_name, b_type_name
|
||||
)))
|
||||
self.call_or_unsupported(a, b, "__and__", "__rand__", "&")
|
||||
}
|
||||
|
||||
pub fn _eq(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult {
|
||||
|
||||
Reference in new issue
Block a user