diff --git a/shared-bindings/util.c b/shared-bindings/util.c index 5c5eafad4a..78960a7552 100644 --- a/shared-bindings/util.c +++ b/shared-bindings/util.c @@ -37,5 +37,17 @@ void raise_deinited_error(void) { mp_raise_ValueError(translate("Object has been deinitialized and can no longer be used. Create a new object.")); } +void properties_print_helper(const mp_print_t *print, mp_obj_t self_in, const mp_arg_t *properties, size_t n_properties) { + const mp_obj_type_t *type = mp_obj_get_type(self_in); + mp_printf(print, "%q(", type->name); + for (size_t i = 0; i < n_properties; i++) { + if (i > 0) { + mp_print_str(print, ", "); + } + mp_printf(print, "%q=", properties[i].qst); + mp_obj_print_helper(print, mp_load_attr(self_in, properties[i].qst), PRINT_REPR); + } + mp_print_str(print, ")"); +} #endif // MICROPY_INCLUDED_SHARED_BINDINGS_UTIL_H diff --git a/shared-bindings/util.h b/shared-bindings/util.h index 33454f10ef..b35e903d38 100644 --- a/shared-bindings/util.h +++ b/shared-bindings/util.h @@ -27,7 +27,11 @@ #ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H #define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H +#include "py/mpprint.h" +#include "py/runtime.h" + void raise_deinited_error(void); +void properties_print_helper(const mp_print_t *print, mp_obj_t self_in, const mp_arg_t *properties, size_t n_properties); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H