Skip to content

Commit 52386ca

Browse files
committed
objexcept: Implement explicit __init__ method, useful for subclasses.
1 parent 66ab571 commit 52386ca

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

py/objexcept.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,27 @@ STATIC void exception_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
120120
}
121121
}
122122

123+
STATIC mp_obj_t exc___init__(uint n_args, const mp_obj_t *args) {
124+
mp_obj_exception_t *self = args[0];
125+
mp_obj_t argst = mp_obj_new_tuple(n_args - 1, args + 1);
126+
self->args = argst;
127+
return mp_const_none;
128+
}
129+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(exc___init___obj, 1, MP_OBJ_FUN_ARGS_MAX, exc___init__);
130+
131+
STATIC const mp_map_elem_t exc_locals_dict_table[] = {
132+
{ MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&exc___init___obj },
133+
};
134+
135+
STATIC MP_DEFINE_CONST_DICT(exc_locals_dict, exc_locals_dict_table);
136+
123137
const mp_obj_type_t mp_type_BaseException = {
124138
{ &mp_type_type },
125139
.name = MP_QSTR_BaseException,
126140
.print = mp_obj_exception_print,
127141
.make_new = mp_obj_exception_make_new,
128142
.load_attr = exception_load_attr,
143+
.locals_dict = (mp_obj_t)&exc_locals_dict,
129144
};
130145

131146
#define MP_DEFINE_EXCEPTION_BASE(base_name) \

0 commit comments

Comments
 (0)