diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-02-05 00:51:47 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-02-05 00:51:47 +0000 |
| commit | 35e2a4e6bb319a208af8d3e5c3e59cee7873400a (patch) | |
| tree | abe2bb266bbb011c807a335b839226a6a66f8341 /py/runtime.c | |
| parent | e0723497b3dbce94e6ce2a2dcd59af510f094fa4 (diff) | |
py: Add built-in super.
Diffstat (limited to 'py/runtime.c')
| -rw-r--r-- | py/runtime.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c index c84a28e4c..9327f0d6a 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -129,6 +129,7 @@ void rt_init(void) { mp_map_add_qstr(&map_builtins, MP_QSTR_list, (mp_obj_t)&list_type); mp_map_add_qstr(&map_builtins, MP_QSTR_map, (mp_obj_t)&map_type); mp_map_add_qstr(&map_builtins, MP_QSTR_set, (mp_obj_t)&set_type); + mp_map_add_qstr(&map_builtins, MP_QSTR_super, (mp_obj_t)&super_type); mp_map_add_qstr(&map_builtins, MP_QSTR_tuple, (mp_obj_t)&tuple_type); mp_map_add_qstr(&map_builtins, MP_QSTR_type, (mp_obj_t)&mp_const_type); mp_map_add_qstr(&map_builtins, MP_QSTR_zip, (mp_obj_t)&zip_type); @@ -852,7 +853,10 @@ static void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) { // if nothing found yet, look for built-in and generic names if (dest[0] == MP_OBJ_NULL) { - if (attr == MP_QSTR___next__ && type->iternext != NULL) { + if (attr == MP_QSTR___class__) { + // a.__class__ is equivalent to type(a) + dest[0] = type; + } else if (attr == MP_QSTR___next__ && type->iternext != NULL) { dest[0] = (mp_obj_t)&mp_builtin_next_obj; dest[1] = base; } else if (type->load_attr == NULL) { |
