From e566670153adc1d995206eaf3a9e606000a789d4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 31 Mar 2014 04:43:21 +0300 Subject: [PATCH] objtype: Add virtual __name__ attribute. It's virtual because it's not shown in dir(...). (That's also how CPython has it). --- py/objtype.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/py/objtype.c b/py/objtype.c index 1275124803..ee3ce12abe 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -297,6 +297,10 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj STATIC void type_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { assert(MP_OBJ_IS_TYPE(self_in, &mp_type_type)); mp_obj_type_t *self = self_in; + if (attr == MP_QSTR___name__) { + dest[0] = MP_OBJ_NEW_QSTR(self->name); + return; + } mp_obj_t member = mp_obj_class_lookup(self, attr); if (member != MP_OBJ_NULL) { // check if the methods are functions, static or class methods