Skip to content

Commit 6c5a152

Browse files
authored
Merge pull request adafruit#1028 from dhalbert/class-property-fix
do not call property if referenced by class, not object
2 parents bfe14ff + 6dfa527 commit 6c5a152

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

py/runtime.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,8 @@ void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t
10601060
dest[1] = self;
10611061
}
10621062
#if MICROPY_PY_BUILTINS_PROPERTY
1063-
} else if (MP_OBJ_IS_TYPE(member, &mp_type_property) && mp_obj_is_native_type(type)) {
1063+
// If self is MP_OBJ_NULL, we looking at the class itself, not an instance.
1064+
} else if (MP_OBJ_IS_TYPE(member, &mp_type_property) && mp_obj_is_native_type(type) && self != MP_OBJ_NULL) {
10641065
// object member is a property; delegate the load to the property
10651066
// Note: This is an optimisation for code size and execution time.
10661067
// The proper way to do it is have the functionality just below
@@ -1161,7 +1162,8 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
11611162
assert(type->locals_dict->base.type == &mp_type_dict); // Micro Python restriction, for now
11621163
mp_map_t *locals_map = &type->locals_dict->map;
11631164
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
1164-
if (elem != NULL && MP_OBJ_IS_TYPE(elem->value, &mp_type_property)) {
1165+
// If base is MP_OBJ_NULL, we looking at the class itself, not an instance.
1166+
if (elem != NULL && MP_OBJ_IS_TYPE(elem->value, &mp_type_property) && base != MP_OBJ_NULL) {
11651167
// attribute exists and is a property; delegate the store/delete
11661168
// Note: This is an optimisation for code size and execution time.
11671169
// The proper way to do it is have the functionality just below in

0 commit comments

Comments
 (0)