Skip to content

Commit 0140719

Browse files
committed
Added default __and__
For all objects without defined __and__ this should be a default error
1 parent 7e10671 commit 0140719

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

vm/src/obj/objobject.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,28 @@ pub fn init(context: &PyContext) {
101101
object.set_attr("__hash__", context.new_rustfunc(object_hash));
102102
object.set_attr("__str__", context.new_rustfunc(object_str));
103103
object.set_attr("__repr__", context.new_rustfunc(object_repr));
104+
object.set_attr("__and__", context.new_rustfunc(object_and));
104105
}
105106

106107
fn object_init(vm: &mut VirtualMachine, _args: PyFuncArgs) -> PyResult {
107108
Ok(vm.ctx.none())
108109
}
109110

111+
fn object_and(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
112+
arg_check!(
113+
vm,
114+
args,
115+
required = [
116+
(zelf, None),
117+
(other, None)
118+
]
119+
);
120+
121+
let zelf_type = objtype::get_type_name(&zelf.typ());
122+
let other_type = objtype::get_type_name(&other.typ());
123+
Err(vm.new_type_error(format!("unsupported operand type(s) for &: {:?} and {:?}", zelf_type, other_type)))
124+
}
125+
110126
fn object_dict(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
111127
match args.args[0].borrow().kind {
112128
PyObjectKind::Class { ref dict, .. } => Ok(dict.clone()),

0 commit comments

Comments
 (0)