Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0140719

Browse files
committed
Added default __and__
For all objects without defined __and__ this should be a default error
1 parent7e10671 commit0140719

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
fnobject_init(vm:&mutVirtualMachine,_args:PyFuncArgs) ->PyResult{
107108
Ok(vm.ctx.none())
108109
}
109110

111+
fnobject_and(vm:&mutVirtualMachine,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
fnobject_dict(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
111127
match args.args[0].borrow().kind{
112128
PyObjectKind::Class{ref dict, ..} =>Ok(dict.clone()),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp