py: Allow retrieving a function's __name__.
Disabled by default. Enabled on unix and stmhal ports.
This commit is contained in:
@@ -70,6 +70,15 @@ STATIC mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_PY_FUNCTION_ATTRS
|
||||
STATIC void bound_meth_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
if(attr == MP_QSTR___name__) {
|
||||
mp_obj_bound_meth_t *o = self_in;
|
||||
dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(o->meth));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const mp_obj_type_t bound_meth_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_bound_method,
|
||||
@@ -77,6 +86,9 @@ const mp_obj_type_t bound_meth_type = {
|
||||
.print = bound_meth_print,
|
||||
#endif
|
||||
.call = bound_meth_call,
|
||||
#if MICROPY_PY_FUNCTION_ATTRS
|
||||
.load_attr = bound_meth_load_attr,
|
||||
#endif
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self) {
|
||||
|
||||
Reference in New Issue
Block a user