diff options
author | Damien George <damien.p.george@gmail.com> | 2017-11-30 10:31:42 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-12-12 16:43:16 +1100 |
commit | d32d22dfd79439e07739166eaa3f7e41466c7ec8 (patch) | |
tree | f34ee1c2af69d7f975f3762da70c5c947f58d8f0 /py/objexcept.c | |
parent | d3f82bc42576ccd80206a17a4941fd5c28c56530 (diff) |
py/objtype: Implement better support for overriding native's __init__.
This patch cleans up and generalises part of the code which handles
overriding and calling a native base-class's __init__ method. It defers
the call to the native make_new() function until after the user (Python)
__init__() method has run. That user method now has the chance to call the
native __init__/make_new and pass it different arguments. If the user
doesn't call the super().__init__ method then it will be called
automatically after the user code finishes, to finalise construction of the
instance.
Diffstat (limited to 'py/objexcept.c')
-rw-r--r-- | py/objexcept.c | 15 |
1 files changed, 0 insertions, 15 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index 380bc3534..524f105ce 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -212,27 +212,12 @@ STATIC void exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t exc___init__(size_t n_args, const mp_obj_t *args) { - mp_obj_exception_t *self = MP_OBJ_TO_PTR(args[0]); - mp_obj_t argst = mp_obj_new_tuple(n_args - 1, args + 1); - self->args = MP_OBJ_TO_PTR(argst); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(exc___init___obj, 1, MP_OBJ_FUN_ARGS_MAX, exc___init__); - -STATIC const mp_rom_map_elem_t exc_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&exc___init___obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(exc_locals_dict, exc_locals_dict_table); - const mp_obj_type_t mp_type_BaseException = { { &mp_type_type }, .name = MP_QSTR_BaseException, .print = mp_obj_exception_print, .make_new = mp_obj_exception_make_new, .attr = exception_attr, - .locals_dict = (mp_obj_dict_t*)&exc_locals_dict, }; #define MP_DEFINE_EXCEPTION(exc_name, base_name) \ |