Skip to content

Commit 783cc4d

Browse files
committed
Added type hints to displayio
1 parent 9b4ffc0 commit 783cc4d

12 files changed

Lines changed: 60 additions & 60 deletions

File tree

shared-bindings/displayio/Bitmap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar
7373

7474
return MP_OBJ_FROM_PTR(self);
7575
}
76-
//| width: Any = ...
76+
//| width: int = ...
7777
//| """Width of the bitmap. (read only)"""
7878
//|
7979
STATIC mp_obj_t displayio_bitmap_obj_get_width(mp_obj_t self_in) {
@@ -91,7 +91,7 @@ const mp_obj_property_t displayio_bitmap_width_obj = {
9191
(mp_obj_t)&mp_const_none_obj},
9292
};
9393

94-
//| height: Any = ...
94+
//| height: int = ...
9595
//| """Height of the bitmap. (read only)"""
9696
//|
9797
STATIC mp_obj_t displayio_bitmap_obj_get_height(mp_obj_t self_in) {
@@ -109,7 +109,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = {
109109
(mp_obj_t)&mp_const_none_obj},
110110
};
111111

112-
//| def __getitem__(self, index: Any) -> Any:
112+
//| def __getitem__(self, index: Union[Tuple[int, int], int]) -> int:
113113
//| """Returns the value at the given index. The index can either be an x,y tuple or an int equal
114114
//| to ``y * width + x``.
115115
//|
@@ -118,7 +118,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = {
118118
//| print(bitmap[0,1])"""
119119
//| ...
120120
//|
121-
//| def __setitem__(self, index: Any, value: Any) -> Any:
121+
//| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None:
122122
//| """Sets the value at the given index. The index can either be an x,y tuple or an int equal
123123
//| to ``y * width + x``.
124124
//|
@@ -172,7 +172,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
172172
return mp_const_none;
173173
}
174174

175-
//| def fill(self, value: Any) -> Any:
175+
//| def fill(self, value: int) -> None:
176176
//| """Fills the bitmap with the supplied palette index value."""
177177
//| ...
178178
//|

shared-bindings/displayio/ColorConverter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz
6565
return MP_OBJ_FROM_PTR(self);
6666
}
6767

68-
//| def convert(self, color: Any) -> Any:
68+
//| def convert(self, color: int) -> int:
6969
//| """Converts the given RGB888 color to RGB565"""
7070
//| ...
7171
//|
@@ -84,7 +84,7 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t
8484
}
8585
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_convert_obj, displayio_colorconverter_obj_convert);
8686

87-
//| dither: Any = ...
87+
//| dither: bool = ...
8888
//| """When true the color converter dithers the output by adding random noise when
8989
//| truncating to display bitdepth"""
9090
//|

shared-bindings/displayio/Display.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//| Most people should not use this class directly. Use a specific display driver instead that will
5050
//| contain the initialization sequence at minimum."""
5151
//|
52-
//| def __init__(self, display_bus: Any, init_sequence: buffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, set_vertical_scroll: int = 0, backlight_pin: microcontroller.Pin = None, brightness_command: int = None, brightness: bool = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60):
52+
//| def __init__(self, display_bus: displayio, init_sequence: buffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, set_vertical_scroll: int = 0, backlight_pin: microcontroller.Pin = None, brightness_command: int = None, brightness: bool = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60):
5353
//| r"""Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
5454
//|
5555
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
@@ -188,7 +188,7 @@ static displayio_display_obj_t* native_display(mp_obj_t display_obj) {
188188
return MP_OBJ_TO_PTR(native_display);
189189
}
190190

191-
//| def show(self, group: Group) -> Any:
191+
//| def show(self, group: Group) -> None:
192192
//| """Switches to displaying the given group of layers. When group is None, the default
193193
//| CircuitPython terminal will be shown.
194194
//|
@@ -210,7 +210,7 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
210210
}
211211
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
212212

213-
//| def refresh(self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1) -> Any:
213+
//| def refresh(self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1) -> bool:
214214
//| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
215215
//| returning True. If the call has taken too long since the last refresh call for the given
216216
//| target frame rate, then the refresh returns False immediately without updating the screen to
@@ -245,7 +245,7 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
245245
}
246246
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);
247247

248-
//| auto_refresh: Any = ...
248+
//| auto_refresh: None = ...
249249
//| """True when the display is refreshed automatically."""
250250
//|
251251
STATIC mp_obj_t displayio_display_obj_get_auto_refresh(mp_obj_t self_in) {
@@ -270,7 +270,7 @@ const mp_obj_property_t displayio_display_auto_refresh_obj = {
270270
(mp_obj_t)&mp_const_none_obj},
271271
};
272272

273-
//| brightness: Any = ...
273+
//| brightness: float = ...
274274
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
275275
//| `auto_brightness` is True, the value of `brightness` will change automatically.
276276
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False."""
@@ -307,7 +307,7 @@ const mp_obj_property_t displayio_display_brightness_obj = {
307307
(mp_obj_t)&mp_const_none_obj},
308308
};
309309

310-
//| auto_brightness: Any = ...
310+
//| auto_brightness: Optional[bool] = ...
311311
//| """True when the display brightness is adjusted automatically, based on an ambient
312312
//| light sensor or other method. Note that some displays may have this set to True by default,
313313
//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
@@ -338,7 +338,7 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = {
338338

339339

340340

341-
//| width: Any = ...
341+
//| width: int = ...
342342
//| Gets the width of the board
343343
//|
344344
//|
@@ -355,7 +355,7 @@ const mp_obj_property_t displayio_display_width_obj = {
355355
(mp_obj_t)&mp_const_none_obj},
356356
};
357357

358-
//| height: Any = ...
358+
//| height: int = ...
359359
//| """Gets the height of the board"""
360360
//|
361361
//|
@@ -372,7 +372,7 @@ const mp_obj_property_t displayio_display_height_obj = {
372372
(mp_obj_t)&mp_const_none_obj},
373373
};
374374

375-
//| rotation: Any = ...
375+
//| rotation: Optional[int] = ...
376376
//| """The rotation of the display as an int in degrees."""
377377
//|
378378
STATIC mp_obj_t displayio_display_obj_get_rotation(mp_obj_t self_in) {
@@ -395,7 +395,7 @@ const mp_obj_property_t displayio_display_rotation_obj = {
395395
(mp_obj_t)&mp_const_none_obj},
396396
};
397397

398-
//| bus: Any = ...
398+
//| bus: displayio = ...
399399
//| """The bus being used by the display"""
400400
//|
401401
//|
@@ -413,7 +413,7 @@ const mp_obj_property_t displayio_display_bus_obj = {
413413
};
414414

415415

416-
//| def fill_row(self, y: int, buffer: bytearray) -> Any:
416+
//| def fill_row(self, y: int, buffer: WriteableBuffer) -> bytearray:
417417
//| """Extract the pixels from a single row
418418
//|
419419
//| :param int y: The top edge of the area

shared-bindings/displayio/EPaperDisplay.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//| Most people should not use this class directly. Use a specific display driver instead that will
5050
//| contain the startup and shutdown sequences at minimum."""
5151
//|
52-
//| def __init__(self, display_bus: Any, start_sequence: buffer, stop_sequence: buffer, *, width: int, height: int, ram_width: int, ram_height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, set_column_window_command: int = None, set_row_window_command: int = None, single_byte_bounds: Any = False, write_black_ram_command: int, black_bits_inverted: bool = False, write_color_ram_command: int = None, color_bits_inverted: bool = False, highlight_color: int = 0x000000, refresh_display_command: int, refresh_time: float = 40, busy_pin: microcontroller.Pin = None, busy_state: bool = True, seconds_per_frame: float = 180, always_toggle_chip_select: bool = False):
52+
//| def __init__(self, display_bus: displayio, start_sequence: buffer, stop_sequence: buffer, *, width: int, height: int, ram_width: int, ram_height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, set_column_window_command: int = None, set_row_window_command: int = None, single_byte_bounds: bool = False, write_black_ram_command: int, black_bits_inverted: bool = False, write_color_ram_command: int = None, color_bits_inverted: bool = False, highlight_color: int = 0x000000, refresh_display_command: int, refresh_time: float = 40, busy_pin: microcontroller.Pin = None, busy_state: bool = True, seconds_per_frame: float = 180, always_toggle_chip_select: bool = False):
5353
//| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
5454
//|
5555
//| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every
@@ -168,7 +168,7 @@ static displayio_epaperdisplay_obj_t* native_display(mp_obj_t display_obj) {
168168
return MP_OBJ_TO_PTR(native_display);
169169
}
170170

171-
//| def show(self, group: Group) -> Any:
171+
//| def show(self, group: Group) -> None:
172172
//| """Switches to displaying the given group of layers. When group is None, the default
173173
//| CircuitPython terminal will be shown.
174174
//|
@@ -190,7 +190,7 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t grou
190190
}
191191
MP_DEFINE_CONST_FUN_OBJ_2(displayio_epaperdisplay_show_obj, displayio_epaperdisplay_obj_show);
192192

193-
//| def refresh(self) -> Any:
193+
//| def refresh(self) -> None:
194194
//| """Refreshes the display immediately or raises an exception if too soon. Use
195195
//| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur."""
196196
//| ...
@@ -205,7 +205,7 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_refresh(mp_obj_t self_in) {
205205
}
206206
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_refresh_obj, displayio_epaperdisplay_obj_refresh);
207207

208-
//| time_to_refresh: Any = ...
208+
//| time_to_refresh: float = ...
209209
//| """Time, in fractional seconds, until the ePaper display can be refreshed."""
210210
//|
211211
STATIC mp_obj_t displayio_epaperdisplay_obj_get_time_to_refresh(mp_obj_t self_in) {
@@ -221,7 +221,7 @@ const mp_obj_property_t displayio_epaperdisplay_time_to_refresh_obj = {
221221
(mp_obj_t)&mp_const_none_obj},
222222
};
223223

224-
//| width: Any = ...
224+
//| width: int = ...
225225
//| """Gets the width of the display in pixels"""
226226
//|
227227
STATIC mp_obj_t displayio_epaperdisplay_obj_get_width(mp_obj_t self_in) {
@@ -237,7 +237,7 @@ const mp_obj_property_t displayio_epaperdisplay_width_obj = {
237237
(mp_obj_t)&mp_const_none_obj},
238238
};
239239

240-
//| height: Any = ...
240+
//| height: int = ...
241241
//| """Gets the height of the display in pixels"""
242242
//|
243243
STATIC mp_obj_t displayio_epaperdisplay_obj_get_height(mp_obj_t self_in) {
@@ -253,7 +253,7 @@ const mp_obj_property_t displayio_epaperdisplay_height_obj = {
253253
(mp_obj_t)&mp_const_none_obj},
254254
};
255255

256-
//| bus: Any = ...
256+
//| bus: displayio = ...
257257
//| """The bus being used by the display"""
258258
//|
259259
STATIC mp_obj_t displayio_epaperdisplay_obj_get_bus(mp_obj_t self_in) {

shared-bindings/displayio/FourWire.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
9696
return self;
9797
}
9898

99-
//| def reset(self) -> Any:
99+
//| def reset(self) -> None:
100100
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
101101
//| is available."""
102102
//| ...
@@ -111,7 +111,7 @@ STATIC mp_obj_t displayio_fourwire_obj_reset(mp_obj_t self_in) {
111111
}
112112
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_reset_obj, displayio_fourwire_obj_reset);
113113

114-
//| def send(self, command: Any, data: Any, *, toggle_every_byte: Any = False) -> Any:
114+
//| def send(self, command: int, data: FourWire, *, toggle_every_byte: bool = False) -> None:
115115
//| """Sends the given command value followed by the full set of data. Display state, such as
116116
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
117117
//| ...

shared-bindings/displayio/Group.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ displayio_group_t* native_group(mp_obj_t group_obj) {
8686
return MP_OBJ_TO_PTR(native_group);
8787
}
8888

89-
//| hidden: Any = ...
89+
//| hidden: Optional[bool] = ...
9090
//| """True when the Group and all of it's layers are not visible. When False, the Group's layers
9191
//| are visible if they haven't been hidden."""
9292
//|
@@ -111,7 +111,7 @@ const mp_obj_property_t displayio_group_hidden_obj = {
111111
(mp_obj_t)&mp_const_none_obj},
112112
};
113113

114-
//| scale: Any = ...
114+
//| scale: Optional[int] = ...
115115
//| """Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
116116
//| will be represented by 2x2 pixels."""
117117
//|
@@ -140,7 +140,7 @@ const mp_obj_property_t displayio_group_scale_obj = {
140140
(mp_obj_t)&mp_const_none_obj},
141141
};
142142

143-
//| x: Any = ...
143+
//| x: Optional[int] = ...
144144
//| """X position of the Group in the parent."""
145145
//|
146146
STATIC mp_obj_t displayio_group_obj_get_x(mp_obj_t self_in) {
@@ -165,7 +165,7 @@ const mp_obj_property_t displayio_group_x_obj = {
165165
(mp_obj_t)&mp_const_none_obj},
166166
};
167167

168-
//| y: Any = ...
168+
//| y: Optional[int] = ...
169169
//| """Y position of the Group in the parent."""
170170
//|
171171
STATIC mp_obj_t displayio_group_obj_get_y(mp_obj_t self_in) {
@@ -190,7 +190,7 @@ const mp_obj_property_t displayio_group_y_obj = {
190190
(mp_obj_t)&mp_const_none_obj},
191191
};
192192

193-
//| def append(self, layer: Any) -> Any:
193+
//| def append(self, layer: layer) -> None:
194194
//| """Append a layer to the group. It will be drawn above other layers."""
195195
//| ...
196196
//|
@@ -201,7 +201,7 @@ STATIC mp_obj_t displayio_group_obj_append(mp_obj_t self_in, mp_obj_t layer) {
201201
}
202202
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_append_obj, displayio_group_obj_append);
203203

204-
//| def insert(self, index: Any, layer: Any) -> Any:
204+
//| def insert(self, index: int, layer: layer) -> None:
205205
//| """Insert a layer into the group."""
206206
//| ...
207207
//|
@@ -214,7 +214,7 @@ STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj,
214214
MP_DEFINE_CONST_FUN_OBJ_3(displayio_group_insert_obj, displayio_group_obj_insert);
215215

216216

217-
//| def index(self, layer: Any) -> Any:
217+
//| def index(self, layer: layer) -> int:
218218
//| """Returns the index of the first copy of layer. Raises ValueError if not found."""
219219
//| ...
220220
//|
@@ -228,7 +228,7 @@ STATIC mp_obj_t displayio_group_obj_index(mp_obj_t self_in, mp_obj_t layer) {
228228
}
229229
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_index_obj, displayio_group_obj_index);
230230

231-
//| def pop(self, i: Any = -1) -> Any:
231+
//| def pop(self, i: int = -1) -> group:
232232
//| """Remove the ith item and return it."""
233233
//| ...
234234
//|
@@ -251,7 +251,7 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args,
251251
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_pop_obj, 1, displayio_group_obj_pop);
252252

253253

254-
//| def remove(self, layer: Any) -> Any:
254+
//| def remove(self, layer: layer) -> None:
255255
//| """Remove the first copy of layer. Raises ValueError if it is not present."""
256256
//| ...
257257
//|
@@ -264,7 +264,7 @@ STATIC mp_obj_t displayio_group_obj_remove(mp_obj_t self_in, mp_obj_t layer) {
264264
}
265265
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_remove_obj, displayio_group_obj_remove);
266266

267-
//| def __len__(self) -> Any:
267+
//| def __len__(self) -> Union[bool, int, None]:
268268
//| """Returns the number of layers in a Group"""
269269
//| ...
270270
//|
@@ -278,23 +278,23 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
278278
}
279279
}
280280

281-
//| def __getitem__(self, index: Any) -> Any:
281+
//| def __getitem__(self, index: int) -> group:
282282
//| """Returns the value at the given index.
283283
//|
284284
//| This allows you to::
285285
//|
286286
//| print(group[0])"""
287287
//| ...
288288
//|
289-
//| def __setitem__(self, index: Any, value: Any) -> Any:
289+
//| def __setitem__(self, index: int, value: group) -> None:
290290
//| """Sets the value at the given index.
291291
//|
292292
//| This allows you to::
293293
//|
294294
//| group[0] = sprite"""
295295
//| ...
296296
//|
297-
//| def __delitem__(self, index: Any) -> Any:
297+
//| def __delitem__(self, index: int) -> group:
298298
//| """Deletes the value at the given index.
299299
//|
300300
//| This allows you to::

shared-bindings/displayio/I2CDisplay.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
7676
return self;
7777
}
7878

79-
//| def reset(self) -> Any:
79+
//| def reset(self) -> None:
8080
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
8181
//| is available."""
8282
//| ...
@@ -91,7 +91,7 @@ STATIC mp_obj_t displayio_i2cdisplay_obj_reset(mp_obj_t self_in) {
9191
}
9292
MP_DEFINE_CONST_FUN_OBJ_1(displayio_i2cdisplay_reset_obj, displayio_i2cdisplay_obj_reset);
9393

94-
//| def send(self, command: Any, data: Any) -> Any:
94+
//| def send(self, command: int, data: displayio) -> None:
9595
//| """Sends the given command value followed by the full set of data. Display state, such as
9696
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
9797
//| ...

shared-bindings/displayio/OnDiskBitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_
8989
return MP_OBJ_FROM_PTR(self);
9090
}
9191

92-
//| width: Any = ...
92+
//| width: int = ...
9393
//| """Width of the bitmap. (read only)"""
9494
//|
9595
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_width(mp_obj_t self_in) {
@@ -108,7 +108,7 @@ const mp_obj_property_t displayio_ondiskbitmap_width_obj = {
108108

109109
};
110110

111-
//| height: Any = ...
111+
//| height: int = ...
112112
//| """Height of the bitmap. (read only)"""
113113
//|
114114
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_height(mp_obj_t self_in) {

0 commit comments

Comments
 (0)