From 0a1e36d2986a76d6e7eea2df6e09c73f1bbe38c4 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 24 Oct 2023 15:39:49 -0700 Subject: [PATCH] Add friendlier error when .show() used Fixes #8499 --- locale/circuitpython.pot | 6 ++++++ shared-bindings/busdisplay/BusDisplay.c | 8 ++++++++ shared-bindings/epaperdisplay/EPaperDisplay.c | 8 ++++++++ shared-bindings/framebufferio/FramebufferDisplay.c | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index dbffabe6b4..98a8d01e4f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -434,6 +434,12 @@ msgstr "" msgid ", in %q\n" msgstr "" +#: shared-bindings/displayio/Display.c +#: shared-bindings/displayio/EPaperDisplay.c +#: shared-bindings/framebufferio/FramebufferDisplay.c +msgid ".show(x) removed. Use .root_group = x" +msgstr "" + #: py/objcomplex.c msgid "0.0 to a complex power" msgstr "" diff --git a/shared-bindings/busdisplay/BusDisplay.c b/shared-bindings/busdisplay/BusDisplay.c index f5571f4040..0566fa609f 100644 --- a/shared-bindings/busdisplay/BusDisplay.c +++ b/shared-bindings/busdisplay/BusDisplay.c @@ -245,6 +245,13 @@ static busdisplay_busdisplay_obj_t *native_display(mp_obj_t display_obj) { return MP_OBJ_TO_PTR(native_display); } +// Undocumented show() implementation with a friendly error message. +STATIC mp_obj_t busdisplay_busdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) { + mp_raise_AttributeError(translate(".show(x) removed. Use .root_group = x")); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(busdisplay_busdisplay_show_obj, busdisplay_busdisplay_obj_show); + //| def refresh( //| self, //| *, @@ -491,6 +498,7 @@ STATIC mp_obj_t busdisplay_busdisplay_obj_fill_row(size_t n_args, const mp_obj_t MP_DEFINE_CONST_FUN_OBJ_KW(busdisplay_busdisplay_fill_row_obj, 1, busdisplay_busdisplay_obj_fill_row); STATIC const mp_rom_map_elem_t busdisplay_busdisplay_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&busdisplay_busdisplay_show_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&busdisplay_busdisplay_refresh_obj) }, { MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&busdisplay_busdisplay_fill_row_obj) }, diff --git a/shared-bindings/epaperdisplay/EPaperDisplay.c b/shared-bindings/epaperdisplay/EPaperDisplay.c index 8c488fffcc..15806be253 100644 --- a/shared-bindings/epaperdisplay/EPaperDisplay.c +++ b/shared-bindings/epaperdisplay/EPaperDisplay.c @@ -246,6 +246,13 @@ static epaperdisplay_epaperdisplay_obj_t *native_display(mp_obj_t display_obj) { return MP_OBJ_TO_PTR(native_display); } +// Undocumented show() implementation with a friendly error message. +STATIC mp_obj_t epaperdisplay_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) { + mp_raise_AttributeError(translate(".show(x) removed. Use .root_group = x")); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(epaperdisplay_epaperdisplay_show_obj, epaperdisplay_epaperdisplay_obj_show); + //| def update_refresh_mode( //| self, start_sequence: ReadableBuffer, seconds_per_frame: float = 180 //| ) -> None: @@ -391,6 +398,7 @@ MP_PROPERTY_GETSET(epaperdisplay_epaperdisplay_root_group_obj, (mp_obj_t)&epaperdisplay_epaperdisplay_set_root_group_obj); STATIC const mp_rom_map_elem_t epaperdisplay_epaperdisplay_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&epaperdisplay_epaperdisplay_show_obj) }, { MP_ROM_QSTR(MP_QSTR_update_refresh_mode), MP_ROM_PTR(&epaperdisplay_epaperdisplay_update_refresh_mode_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&epaperdisplay_epaperdisplay_refresh_obj) }, diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 370d2eacae..03019e739a 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -98,6 +98,13 @@ static framebufferio_framebufferdisplay_obj_t *native_display(mp_obj_t display_o return MP_OBJ_TO_PTR(native_display); } +// Undocumented show() implementation with a friendly error message. +STATIC mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) { + mp_raise_AttributeError(translate(".show(x) removed. Use .root_group = x")); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_show_obj, framebufferio_framebufferdisplay_obj_show); + //| def refresh( //| self, //| *, @@ -348,6 +355,7 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_root_group_obj, (mp_obj_t)&framebufferio_framebufferdisplay_set_root_group_obj); STATIC const mp_rom_map_elem_t framebufferio_framebufferdisplay_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&framebufferio_framebufferdisplay_show_obj) }, { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_refresh_obj) }, { MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&framebufferio_framebufferdisplay_fill_row_obj) },