Skip to content

Commit 7894627

Browse files
committed
Use extend_class in objtype.
1 parent dfb24d7 commit 7894627

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

vm/src/obj/objtype.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,23 @@ pub fn create_type(type_type: PyObjectRef, object_type: PyObjectRef, _dict_type:
4141
}
4242
}
4343

44-
pub fn init(context: &PyContext) {
45-
let type_type = &context.type_type;
46-
44+
pub fn init(ctx: &PyContext) {
4745
let type_doc = "type(object_or_name, bases, dict)\n\
4846
type(object) -> the object's type\n\
4947
type(name, bases, dict) -> a new type";
5048

51-
context.set_attr(&type_type, "__call__", context.new_rustfunc(type_call));
52-
context.set_attr(&type_type, "__new__", context.new_rustfunc(type_new));
53-
context.set_attr(&type_type, "__mro__", context.new_property(type_mro));
54-
context.set_attr(&type_type, "__repr__", context.new_rustfunc(type_repr));
55-
context.set_attr(
56-
&type_type,
57-
"__prepare__",
58-
context.new_rustfunc(type_prepare),
59-
);
60-
context.set_attr(
61-
&type_type,
62-
"__getattribute__",
63-
context.new_rustfunc(type_getattribute),
64-
);
65-
context.set_attr(
66-
&type_type,
67-
"__instancecheck__",
68-
context.new_rustfunc(type_instance_check),
69-
);
70-
context.set_attr(
71-
&type_type,
72-
"__subclasscheck__",
73-
context.new_rustfunc(type_subclass_check),
74-
);
75-
context.set_attr(&type_type, "__doc__", context.new_str(type_doc.to_string()));
76-
context.set_attr(&type_type, "__dir__", context.new_rustfunc(type_dir));
49+
extend_class!(&ctx, &ctx.type_type, {
50+
"__call__" => ctx.new_rustfunc(type_call),
51+
"__new__" => ctx.new_rustfunc(type_new),
52+
"__mro__" => ctx.new_property(type_mro),
53+
"__repr__" => ctx.new_rustfunc(type_repr),
54+
"__prepare__" => ctx.new_rustfunc(type_prepare),
55+
"__getattribute__" => ctx.new_rustfunc(type_getattribute),
56+
"__instancecheck__" => ctx.new_rustfunc(type_instance_check),
57+
"__subclasscheck__" => ctx.new_rustfunc(type_subclass_check),
58+
"__doc__" => ctx.new_str(type_doc.to_string()),
59+
"__dir__" => ctx.new_rustfunc(type_dir),
60+
});
7761
}
7862

7963
fn type_mro(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

0 commit comments

Comments
 (0)