Skip to content

Commit 4517ab8

Browse files
authored
Merge pull request adafruit#709 from jepler/core-class-superproperty
Make test core_class_superproperty.py succeed
2 parents 77938db + 047a4f5 commit 4517ab8

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

py/gc_long_lived.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ mp_obj_property_t *make_property_long_lived(mp_obj_property_t *prop, uint8_t max
7878
if (max_depth == 0) {
7979
return prop;
8080
}
81-
prop->proxy[0] = make_fun_bc_long_lived((mp_obj_fun_bc_t*) prop->proxy[0], max_depth - 1);
82-
prop->proxy[1] = make_fun_bc_long_lived((mp_obj_fun_bc_t*) prop->proxy[1], max_depth - 1);
83-
prop->proxy[2] = make_fun_bc_long_lived((mp_obj_fun_bc_t*) prop->proxy[2], max_depth - 1);
81+
prop->proxy[0] = make_obj_long_lived((mp_obj_fun_bc_t*) prop->proxy[0], max_depth - 1);
82+
prop->proxy[1] = make_obj_long_lived((mp_obj_fun_bc_t*) prop->proxy[1], max_depth - 1);
83+
prop->proxy[2] = make_obj_long_lived((mp_obj_fun_bc_t*) prop->proxy[2], max_depth - 1);
8484
return gc_make_long_lived(prop);
8585
}
8686

py/objtype.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
567567
mp_obj_class_lookup(&lookup, self->base.type);
568568
mp_obj_t member = dest[0];
569569
if (member != MP_OBJ_NULL) {
570+
// changes here may may require changes to super_attr, below
570571
#if MICROPY_PY_BUILTINS_PROPERTY
571572
if (MP_OBJ_IS_TYPE(member, &mp_type_property)) {
572573
// object member is a property; delegate the load to the property
@@ -1112,14 +1113,37 @@ STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
11121113
assert(MP_OBJ_IS_TYPE(items[i], &mp_type_type));
11131114
mp_obj_class_lookup(&lookup, (mp_obj_type_t*)MP_OBJ_TO_PTR(items[i]));
11141115
if (dest[0] != MP_OBJ_NULL) {
1115-
return;
1116+
break;
11161117
}
11171118
}
11181119
} else {
11191120
mp_obj_class_lookup(&lookup, type->parent);
1120-
if (dest[0] != MP_OBJ_NULL) {
1121-
return;
1121+
}
1122+
1123+
if (dest[0] != MP_OBJ_NULL) {
1124+
mp_obj_t member = dest[0];
1125+
// changes to mp_obj_instance_load_attr may require changes
1126+
// here...
1127+
#if MICROPY_PY_BUILTINS_PROPERTY
1128+
if (MP_OBJ_IS_TYPE(member, &mp_type_property)) {
1129+
const mp_obj_t *proxy = mp_obj_property_get(member);
1130+
if (proxy[0] == mp_const_none) {
1131+
mp_raise_AttributeError("unreadable attribute");
1132+
} else {
1133+
dest[0] = mp_call_function_n_kw(proxy[0], 1, 0, &self_in);
1134+
}
1135+
}
1136+
#endif
1137+
#if MICROPY_PY_DESCRIPTORS
1138+
mp_obj_t attr_get_method[4];
1139+
mp_load_method_maybe(member, MP_QSTR___get__, attr_get_method);
1140+
if (attr_get_method[0] != MP_OBJ_NULL) {
1141+
attr_get_method[2] = self_in;
1142+
attr_get_method[3] = MP_OBJ_FROM_PTR(mp_obj_get_type(self_in));
1143+
dest[0] = mp_call_method_n_kw(2, 0, attr_get_method);
11221144
}
1145+
#endif
1146+
return;
11231147
}
11241148

11251149
mp_obj_class_lookup(&lookup, &mp_type_object);

tests/cpydiff/core_class_superproperty.py renamed to tests/basics/core_class_superproperty.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""
2-
categories: Core,Classes
3-
description: Calling super() getter property in subclass will return a property object, not the value
4-
cause: Unknown
5-
workaround: Unknown
2+
test that calling super() getter property in subclass will return the value
63
"""
74
class A:
85
@property

0 commit comments

Comments
 (0)