py: Allow retrieving a function's __name__.
Disabled by default. Enabled on unix and stmhal ports.
diff --git a/py/objboundmeth.c b/py/objboundmeth.c
index 7698ed2..69ae263 100644
--- a/py/objboundmeth.c
+++ b/py/objboundmeth.c
@@ -70,6 +70,15 @@
}
}
+#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 @@
.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) {