diff options
author | Josh Lloyd <j.nevercast@gmail.com> | 2019-09-24 17:01:54 +1200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-10-18 15:20:56 +1100 |
commit | 8f9e2e325ab0d0dfa9457779010a4cb2cfe60fef (patch) | |
tree | 08d4fcea0a6c9c124d50a93013f40cf876e7aa02 /py/objtype.c | |
parent | 59c1b7d4b8fb1d441f9322976582c8709f01dfbe (diff) |
py/objtype: Add type.__bases__ attribute.
Enabled as part of MICROPY_CPYTHON_COMPAT.
Diffstat (limited to 'py/objtype.c')
-rw-r--r-- | py/objtype.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c index 236c79e6a..bf089dc49 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1014,6 +1014,21 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { dest[0] = MP_OBJ_NEW_QSTR(self->name); return; } + if (attr == MP_QSTR___bases__) { + if (self == &mp_type_object) { + dest[0] = mp_const_empty_tuple; + return; + } + mp_obj_t parent_obj = self->parent ? MP_OBJ_FROM_PTR(self->parent) : MP_OBJ_FROM_PTR(&mp_type_object); + #if MICROPY_MULTIPLE_INHERITANCE + if (mp_obj_is_type(parent_obj, &mp_type_tuple)) { + dest[0] = parent_obj; + return; + } + #endif + dest[0] = mp_obj_new_tuple(1, &parent_obj); + return; + } #endif struct class_lookup_data lookup = { .obj = (mp_obj_instance_t*)self, |