Skip to content

Commit 13a4ba7

Browse files
committed
py/objtype: Add __dict__ attribute for class objects.
1 parent 7e374d2 commit 13a4ba7

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ size_t mp_obj_dict_len(mp_obj_t self_in);
772772
mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
773773
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
774774
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key);
775+
mp_obj_t mp_obj_dict_copy(mp_obj_t self_in);
775776
static inline mp_map_t *mp_obj_dict_get_map(mp_obj_t dict) {
776777
return &((mp_obj_dict_t*)MP_OBJ_TO_PTR(dict))->map;
777778
}

py/objdict.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) {
221221
}
222222
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear);
223223

224-
STATIC mp_obj_t dict_copy(mp_obj_t self_in) {
224+
mp_obj_t mp_obj_dict_copy(mp_obj_t self_in) {
225225
mp_check_self(mp_obj_is_dict_type(self_in));
226226
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
227227
mp_obj_t other_out = mp_obj_new_dict(self->map.alloc);
@@ -234,7 +234,7 @@ STATIC mp_obj_t dict_copy(mp_obj_t self_in) {
234234
memcpy(other->map.table, self->map.table, self->map.alloc * sizeof(mp_map_elem_t));
235235
return other_out;
236236
}
237-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, dict_copy);
237+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, mp_obj_dict_copy);
238238

239239
#if MICROPY_PY_BUILTINS_DICT_FROMKEYS
240240
// this is a classmethod

py/objtype.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
10141014
dest[0] = MP_OBJ_NEW_QSTR(self->name);
10151015
return;
10161016
}
1017+
#if MICROPY_CPYTHON_COMPAT
1018+
if (attr == MP_QSTR___dict__) {
1019+
dest[0] = mp_obj_dict_copy(MP_OBJ_FROM_PTR(self->locals_dict));
1020+
return;
1021+
}
1022+
#endif
10171023
if (attr == MP_QSTR___bases__) {
10181024
if (self == &mp_type_object) {
10191025
dest[0] = mp_const_empty_tuple;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy