@@ -41,39 +41,23 @@ pub fn create_type(type_type: PyObjectRef, object_type: PyObjectRef, _dict_type:
41
41
}
42
42
}
43
43
44
- pub fn init ( context : & PyContext ) {
45
- let type_type = & context. type_type ;
46
-
44
+ pub fn init ( ctx : & PyContext ) {
47
45
let type_doc = "type(object_or_name, bases, dict)\n \
48
46
type(object) -> the object's type\n \
49
47
type(name, bases, dict) -> a new type";
50
48
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
+ } ) ;
77
61
}
78
62
79
63
fn type_mro ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
0 commit comments