kopia lustrzana https://github.com/micropython/micropython
py/objboundmeth: Support loading generic attrs from the method.
Instead of assuming that the method is a bytecode object, and only supporting load of __name__, make the operation generic by delegating the load to the method object itself. Saves a bit of code size and fixes the case of attempting to load __name__ on a native method, see issue #4028.pull/4088/head
rodzic
da7355e213
commit
113f00a9ab
|
@ -89,10 +89,9 @@ STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||||
// not load attribute
|
// not load attribute
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (attr == MP_QSTR___name__) {
|
// Delegate the load to the method object
|
||||||
mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(self_in);
|
mp_obj_bound_meth_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(o->meth));
|
mp_load_method_maybe(self->meth, attr, dest);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,10 @@ try:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print('SKIP')
|
print('SKIP')
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
# __name__ of a bound native method is not implemented in uPy
|
||||||
|
# the test here is to make sure it doesn't crash
|
||||||
|
try:
|
||||||
|
str((1).to_bytes.__name__)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
Ładowanie…
Reference in New Issue