py/objmodule: Add support for __dict__.
This matches class `__dict__`, and is similarly gated on MICROPY_CPYTHON_COMPAT. Unlike class though, because modules's globals are actually dict instances, the result is a mutable dictionary. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
d94141e147
commit
15d0615d5c
@@ -89,6 +89,10 @@ STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
|
||||
if (elem != NULL) {
|
||||
dest[0] = elem->value;
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
} else if (attr == MP_QSTR___dict__) {
|
||||
dest[0] = MP_OBJ_FROM_PTR(self->globals);
|
||||
#endif
|
||||
#if MICROPY_MODULE_GETATTR
|
||||
} else if (attr != MP_QSTR___getattr__) {
|
||||
elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(MP_QSTR___getattr__), MP_MAP_LOOKUP);
|
||||
|
||||
Reference in New Issue
Block a user