Skip to content

Commit 54a342a

Browse files
committed
Add and correct some type hints
1 parent 5437084 commit 54a342a

File tree

52 files changed

+266
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+266
-230
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
sudo apt-get install -y eatmydata
3939
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
40-
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort
40+
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort black
4141
- name: Versions
4242
run: |
4343
gcc --version

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "py/objproperty.h"
3131
#include "py/runtime.h"
3232

33-
//| import typing
3433
//| class Clock:
3534
//| """Identifies a clock on the microcontroller.
3635
//|
@@ -62,7 +61,7 @@ const mp_obj_property_t samd_clock_enabled_obj = {
6261
},
6362
};
6463

65-
//| parent: typing.Union(Clock | None) = ...
64+
//| parent: Union[Clock, None] = ...
6665
//| """Clock parent. (read-only)"""
6766
//|
6867
STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {

shared-bindings/_bleio/Adapter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const mp_obj_property_t bleio_adapter_name_obj = {
135135
(mp_obj_t)&mp_const_none_obj },
136136
};
137137

138-
//| def start_advertising(self, data: buf, *, scan_response: buf = None, connectable: bool = True, anonymous: bool = False, timeout: int = 0, interval: float = 0.1) -> None:
138+
//| def start_advertising(self, data: ReadableBuffer, *, scan_response: Optional[ReadableBuffer] = None, connectable: bool = True, anonymous: bool = False, timeout: int = 0, interval: float = 0.1) -> None:
139139
//| """Starts advertising until `stop_advertising` is called or if connectable, another device
140140
//| connects to us.
141141
//|
@@ -215,7 +215,7 @@ STATIC mp_obj_t bleio_adapter_stop_advertising(mp_obj_t self_in) {
215215
}
216216
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapter_stop_advertising);
217217

218-
//| def start_scan(self, prefixes: sequence = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> iterable:
218+
//| def start_scan(self, prefixes: ReadableBuffer = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> Iterable[ScanEntry]:
219219
//| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
220220
//| filtered and returned separately.
221221
//|
@@ -350,11 +350,11 @@ const mp_obj_property_t bleio_adapter_connections_obj = {
350350
(mp_obj_t)&mp_const_none_obj },
351351
};
352352

353-
//| def connect(self, address: Address, *, timeout: float/int) -> Connection:
353+
//| def connect(self, address: Address, *, timeout: float) -> Connection:
354354
//| """Attempts a connection to the device with the given address.
355355
//|
356356
//| :param Address address: The address of the peripheral to connect to
357-
//| :param float/int timeout: Try to connect for timeout seconds."""
357+
//| :param float timeout: Try to connect for timeout seconds."""
358358
//| ...
359359
//|
360360
STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

shared-bindings/_bleio/Address.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const mp_obj_property_t bleio_address_type_obj = {
128128
(mp_obj_t)&mp_const_none_obj},
129129
};
130130

131-
//| def __eq__(self, other: Any) -> bool:
131+
//| def __eq__(self, other: Address) -> bool:
132132
//| """Two Address objects are equal if their addresses and address types are equal."""
133133
//| ...
134134
//|

shared-bindings/_bleio/Characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//| ...
4646
//|
4747

48-
//| def add_to_service(self, service: Service, uuid: UUID, *, properties: int = 0, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: buf = None) -> Characteristic:
48+
//| def add_to_service(self, service: Service, uuid: UUID, *, properties: int = 0, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: Optional[ReadableBuffer] = None) -> Characteristic:
4949
//| """Create a new Characteristic object, and add it to this Service.
5050
//|
5151
//| :param Service service: The service that will provide this characteristic

shared-bindings/_bleio/Connection.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
7171
//| def __init__(self) -> None:
7272
//| """Connections cannot be made directly. Instead, to initiate a connection use `Adapter.connect`.
7373
//| Connections may also be made when another device initiates a connection. To use a Connection
74-
//| created by a peer, read the `Adapter.connections` property.
74+
//| created by a peer, read the `Adapter.connections` property."""
7575
//| ...
7676
//|
77-
//| def disconnect(self) -> Any:
78-
//| ""Disconnects from the remote peripheral. Does nothing if already disconnected."""
77+
//| def disconnect(self) -> None:
78+
//| """Disconnects from the remote peripheral. Does nothing if already disconnected."""
7979
//| ...
8080
//|
8181
STATIC mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) {
@@ -109,7 +109,7 @@ STATIC mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args
109109
}
110110
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection_pair);
111111

112-
//| def discover_remote_services(self, service_uuids_whitelist: iterable = None) -> Service:
112+
//| def discover_remote_services(self, service_uuids_whitelist: Iterable[UUID] = None) -> Tuple[Service, ...]:
113113
//| """Do BLE discovery for all services or for the given service UUIDS,
114114
//| to find their handles and characteristics, and return the discovered services.
115115
//| `Connection.connected` must be True.

shared-bindings/_bleio/UUID.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
248248
}
249249
}
250250

251-
//| def __eq__(self, other: Any) -> bool:
251+
//| def __eq__(self, other: UUID) -> bool:
252252
//| """Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit."""
253253
//| ...
254254
//|

shared-bindings/_pew/PewPew.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,31 @@
4545
//| used internally by it. All user-visible interactions are done through
4646
//| that library."""
4747
//|
48-
49-
//| def __init__(self, buffer: ReadableBuffer, rows: List[DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut], cols: List[DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut], buttons: DigitalInOut) -> None:
48+
//| def __init__(
49+
//| self,
50+
//| buffer: ReadableBuffer,
51+
//| rows: List[
52+
//| digitalio.DigitalInOut,
53+
//| digitalio.DigitalInOut,
54+
//| digitalio.DigitalInOut,
55+
//| digitalio.DigitalInOut,
56+
//| digitalio.DigitalInOut,
57+
//| digitalio.DigitalInOut,
58+
//| digitalio.DigitalInOut,
59+
//| digitalio.DigitalInOut,
60+
//| ],
61+
//| cols: List[
62+
//| digitalio.DigitalInOut,
63+
//| digitalio.DigitalInOut,
64+
//| digitalio.DigitalInOut,
65+
//| digitalio.DigitalInOut,
66+
//| digitalio.DigitalInOut,
67+
//| digitalio.DigitalInOut,
68+
//| digitalio.DigitalInOut,
69+
//| digitalio.DigitalInOut,
70+
//| ],
71+
//| buttons: digitalio.DigitalInOut,
72+
//| ) -> None:
5073
//| """Initializes matrix scanning routines.
5174
//|
5275
//| The ``buffer`` is a 64 byte long ``bytearray`` that stores what should

shared-bindings/_pixelbuf/PixelBuf.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const mp_obj_property_t pixelbuf_pixelbuf_auto_write_obj = {
221221
(mp_obj_t)&mp_const_none_obj},
222222
};
223223

224-
//| byteorder: string = ...
224+
//| byteorder: str = ...
225225
//| """byteorder string for the buffer (read-only)"""
226226
//|
227227
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_byteorder(mp_obj_t self_in) {
@@ -257,7 +257,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_show(mp_obj_t self_in) {
257257
}
258258
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_show);
259259

260-
//| def fill(color: Union[int, Tuple[int, int, int]]) -> None:
260+
//| def fill(self, color: Union[int, Tuple[int, int, int]]) -> None:
261261
//| """Fills the given pixelbuf with the given color."""
262262
//| ...
263263
//|
@@ -269,13 +269,19 @@ STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
269269
}
270270
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_fill);
271271

272-
//| def __getitem__(self, index: int) -> Tuple[int, int, int, Union[int, float]]:
272+
//| @overload
273+
//| def __getitem__(self, index: slice) -> Tuple[Tuple, ...]: ...
274+
//| def __getitem__(self, index: int) -> Tuple:
273275
//| """Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values
274276
//| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel
275277
//| intensity from 0-1.0."""
276278
//| ...
277279
//|
278-
//| def __setitem__(self, index: int, value: Union[int, Tuple[int, int, int, Union[int, float]]]) -> PixelBuf:
280+
//| @overload
281+
//| def __setitem__(self, index: slice, value: Tuple[Union[int, Tuple, List], ...]) -> None: ...
282+
//| @overload
283+
//| def __setitem__(self, index: slice, value: List[Union[int, Tuple, List]]) -> None: ...
284+
//| def __setitem__(self, index: int, value: Union[int, Tuple, List]) -> None:
279285
//| """Sets the pixel value at the given index. Value can either be a tuple or integer. Tuples are
280286
//| The individual (Red, Green, Blue[, White]) values between 0 and 255. If given an integer, the
281287
//| red, green and blue values are packed into the lower three bytes (0xRRGGBB).

shared-bindings/_pixelbuf/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
//| Byteorders are configured with strings, such as "RGB" or "RGBD"."""
4242
// TODO: Pull in docs from pypixelbuf.
4343

44-
//| def colorwheel(n: int) -> int:
44+
//| def colorwheel(n: float) -> int:
4545
//| """C implementation of the common wheel() function found in many examples.
4646
//| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar)."""
4747
//| ...
4848
//|
49-
//| def wheel(n: Any) -> Any:
49+
//| def wheel(n: float) -> int:
5050
//| """Use of wheel() is deprecated. Please use colorwheel()."""
5151
//|
5252

shared-bindings/_stage/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//| The `_stage` module contains native code to speed-up the ```stage`` Library
4040
//| <https://github.com/python-ugame/circuitpython-stage>`_."""
4141
//|
42-
//| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> Any:
42+
//| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> None:
4343
//| """Render and send to the display a fragment of the screen.
4444
//|
4545
//| :param int x0: Left edge of the fragment.

shared-bindings/aesio/aes.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//| class AES:
1313
//| """Encrypt and decrypt AES streams"""
1414
//|
15-
//| def __init__(self, key: Optional[ReadableBuffer], mode: int=0, iv: ReadableBuffer=None, segment_size: int=8) -> None:
15+
//| def __init__(self, key: Optional[ReadableBuffer], mode: int = 0, iv: ReadableBuffer = None, segment_size: int = 8) -> None:
1616
//| """Create a new AES state with the given key.
1717
//|
1818
//| :param bytearray key: A 16-, 24-, or 32-byte key
@@ -152,7 +152,7 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length,
152152
}
153153
}
154154

155-
//| def encrypt_into(src: ReadableBuffer, dest: WriteableBuffer) -> None:
155+
//| def encrypt_into(self, src: ReadableBuffer, dest: WriteableBuffer) -> None:
156156
//| """Encrypt the buffer from ``src`` into ``dest``.
157157
//|
158158
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
@@ -183,8 +183,7 @@ STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src,
183183
STATIC MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj,
184184
aesio_aes_encrypt_into);
185185

186-
//| def decrypt_into(src: ReadableBuffer, dest: WriteableBuffer) -> None:
187-
//|
186+
//| def decrypt_into(self, src: ReadableBuffer, dest: WriteableBuffer) -> None:
188187
//| """Decrypt the buffer from ``src`` into ``dest``.
189188
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
190189
//| buffers must be a multiple of 16 bytes, and must be equal length. For

shared-bindings/audiomixer/Mixer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
211211
(mp_obj_t)&mp_const_none_obj},
212212
};
213213

214-
//| def play(self, sample: Union[audiomixer.WaveFile, audiocore.RawSample, audiomixer.Mixer], *, voice: int = 0, loop: bool = False) -> None:
214+
//| def play(self, sample: Union[audiocore.WaveFile, audiocore.RawSample, Mixer], *, voice: int = 0, loop: bool = False) -> None:
215215
//| """Plays the sample once when loop=False and continuously when loop=True.
216216
//| Does not block. Use `playing` to block.
217217
//|

0 commit comments

Comments
 (0)