@@ -50,7 +50,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
50
50
51
51
STATIC mp_obj_t object___new__ (mp_obj_t cls ) {
52
52
if (!mp_obj_is_type (cls , & mp_type_type ) || !mp_obj_is_instance_type ((mp_obj_type_t * )MP_OBJ_TO_PTR (cls ))) {
53
- mp_raise_TypeError ("__new__ arg must be a user-type" );
53
+ mp_raise_TypeError ("arg must be user-type" );
54
54
}
55
55
// This executes only "__new__" part of instance creation.
56
56
// TODO: This won't work well for classes with native bases.
@@ -62,13 +62,33 @@ STATIC mp_obj_t object___new__(mp_obj_t cls) {
62
62
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (object___new___fun_obj , object___new__ );
63
63
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ (object___new___obj , MP_ROM_PTR (& object___new___fun_obj ));
64
64
65
+ #if MICROPY_PY_DELATTR_SETATTR
66
+ STATIC mp_obj_t object___setattr__ (mp_obj_t self_in , mp_obj_t attr , mp_obj_t value ) {
67
+ if (!mp_obj_is_instance_type (mp_obj_get_type (MP_OBJ_TO_PTR (self_in )))) {
68
+ mp_raise_TypeError ("arg must be user-type" );
69
+ }
70
+
71
+ if (!mp_obj_is_str (attr )) {
72
+ mp_raise_TypeError (NULL );
73
+ }
74
+
75
+ mp_obj_instance_t * self = MP_OBJ_TO_PTR (self_in );
76
+ mp_map_lookup (& self -> members , attr , MP_MAP_LOOKUP_ADD_IF_NOT_FOUND )-> value = value ;
77
+ return mp_const_none ;
78
+ }
79
+ STATIC MP_DEFINE_CONST_FUN_OBJ_3 (object___setattr___obj , object___setattr__ );
80
+ #endif
81
+
65
82
STATIC const mp_rom_map_elem_t object_locals_dict_table [] = {
66
83
#if MICROPY_CPYTHON_COMPAT
67
84
{ MP_ROM_QSTR (MP_QSTR___init__ ), MP_ROM_PTR (& object___init___obj ) },
68
85
#endif
69
86
#if MICROPY_CPYTHON_COMPAT
70
87
{ MP_ROM_QSTR (MP_QSTR___new__ ), MP_ROM_PTR (& object___new___obj ) },
71
88
#endif
89
+ #if MICROPY_PY_DELATTR_SETATTR
90
+ { MP_ROM_QSTR (MP_QSTR___setattr__ ), MP_ROM_PTR (& object___setattr___obj ) },
91
+ #endif
72
92
};
73
93
74
94
STATIC MP_DEFINE_CONST_DICT (object_locals_dict , object_locals_dict_table );
0 commit comments