Skip to content

Commit bc03e03

Browse files
committed
util: Add properties_print_helper
1 parent c22fd2a commit bc03e03

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

shared-bindings/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ void raise_deinited_error(void) {
3737
mp_raise_ValueError(translate("Object has been deinitialized and can no longer be used. Create a new object."));
3838
}
3939

40+
void properties_print_helper(const mp_print_t *print, mp_obj_t self_in, const mp_arg_t *properties, size_t n_properties) {
41+
const mp_obj_type_t *type = mp_obj_get_type(self_in);
42+
mp_printf(print, "%q(", type->name);
43+
for (size_t i = 0; i < n_properties; i++) {
44+
if (i > 0) {
45+
mp_print_str(print, ", ");
46+
}
47+
mp_printf(print, "%q=", properties[i].qst);
48+
mp_obj_print_helper(print, mp_load_attr(self_in, properties[i].qst), PRINT_REPR);
49+
}
50+
mp_print_str(print, ")");
51+
}
4052

4153
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_UTIL_H

shared-bindings/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H
2828
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H
2929

30+
#include "py/mpprint.h"
31+
#include "py/runtime.h"
32+
3033
void raise_deinited_error(void);
34+
void properties_print_helper(const mp_print_t *print, mp_obj_t self_in, const mp_arg_t *properties, size_t n_properties);
3135

3236

3337
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_UTIL_H

0 commit comments

Comments
 (0)