Skip to content

Commit ffc5f0c

Browse files
committed
Added type hints to bitbangio
1 parent ed476a4 commit ffc5f0c

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

shared-bindings/bitbangio/I2C.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
7979
return (mp_obj_t)self;
8080
}
8181

82-
//| def deinit(self, ) -> Any:
82+
//| def deinit(self, ) -> None:
8383
//| """Releases control of the underlying hardware so other classes can use it."""
8484
//| ...
8585
//|
@@ -96,13 +96,13 @@ STATIC void check_for_deinit(bitbangio_i2c_obj_t *self) {
9696
}
9797
}
9898

99-
//| def __enter__(self, ) -> Any:
99+
//| def __enter__(self, ) -> I2C:
100100
//| """No-op used in Context Managers."""
101101
//| ...
102102
//|
103103
// Provided by context manager helper.
104104

105-
//| def __exit__(self, ) -> Any:
105+
//| def __exit__(self, ) -> None:
106106
//| """Automatically deinitializes the hardware on context exit. See
107107
//| :ref:`lifetime-and-contextmanagers` for more info."""
108108
//| ...
@@ -120,7 +120,7 @@ static void check_lock(bitbangio_i2c_obj_t *self) {
120120
}
121121
}
122122

123-
//| def scan(self, ) -> Any:
123+
//| def scan(self, ) -> list:
124124
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
125125
//| those that respond. A device responds if it pulls the SDA line low after
126126
//| its address (including a read bit) is sent on the bus."""
@@ -142,7 +142,7 @@ STATIC mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) {
142142
}
143143
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan);
144144

145-
//| def try_lock(self, ) -> Any:
145+
//| def try_lock(self, ) -> bool:
146146
//| """Attempts to grab the I2C lock. Returns True on success."""
147147
//| ...
148148
//|
@@ -153,7 +153,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) {
153153
}
154154
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock);
155155

156-
//| def unlock(self, ) -> Any:
156+
//| def unlock(self, ) -> None:
157157
//| """Releases the I2C lock."""
158158
//| ...
159159
//|
@@ -165,7 +165,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
165165
}
166166
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
167167

168-
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
168+
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> None:
169169
//| """Read into ``buffer`` from the device selected by ``address``.
170170
//| The number of bytes read will be the length of ``buffer``.
171171
//| At least one byte must be read.
@@ -217,7 +217,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
217217
}
218218
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into);
219219

220-
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
220+
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> None:
221221
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a
222222
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
223223
//| before a read.
@@ -277,7 +277,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
277277
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto);
278278

279279

280-
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
280+
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
281281
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
282282
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
283283
//| ``in_buffer`` can be the same buffer because they are used sequentially.

shared-bindings/bitbangio/OneWire.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a
7878
return MP_OBJ_FROM_PTR(self);
7979
}
8080

81-
//| def deinit(self, ) -> Any:
81+
//| def deinit(self, ) -> None:
8282
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
8383
//| ...
8484
//|
@@ -95,13 +95,13 @@ STATIC void check_for_deinit(bitbangio_onewire_obj_t *self) {
9595
}
9696
}
9797

98-
//| def __enter__(self, ) -> Any:
98+
//| def __enter__(self, ) -> OneWire:
9999
//| """No-op used by Context Managers."""
100100
//| ...
101101
//|
102102
// Provided by context manager helper.
103103

104-
//| def __exit__(self, ) -> Any:
104+
//| def __exit__(self, ) -> None:
105105
//| """Automatically deinitializes the hardware when exiting a context. See
106106
//| :ref:`lifetime-and-contextmanagers` for more info."""
107107
//| ...
@@ -113,7 +113,7 @@ STATIC mp_obj_t bitbangio_onewire_obj___exit__(size_t n_args, const mp_obj_t *ar
113113
}
114114
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_onewire___exit___obj, 4, 4, bitbangio_onewire_obj___exit__);
115115

116-
//| def reset(self, ) -> Any:
116+
//| def reset(self, ) -> bool:
117117
//| """Reset the OneWire bus"""
118118
//| ...
119119
//|
@@ -125,7 +125,7 @@ STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) {
125125
}
126126
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_reset_obj, bitbangio_onewire_obj_reset);
127127

128-
//| def read_bit(self, ) -> Any:
128+
//| def read_bit(self, ) -> bool:
129129
//| """Read in a bit
130130
//|
131131
//| :returns: bit state read
@@ -140,7 +140,7 @@ STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) {
140140
}
141141
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_read_bit_obj, bitbangio_onewire_obj_read_bit);
142142

143-
//| def write_bit(self, value: Any) -> Any:
143+
//| def write_bit(self, value: bool) -> None:
144144
//| """Write out a bit based on value."""
145145
//| ...
146146
//|

shared-bindings/bitbangio/SPI.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
9090
return (mp_obj_t)self;
9191
}
9292

93-
//| def deinit(self, ) -> Any:
93+
//| def deinit(self, ) -> None:
9494
//| """Turn off the SPI bus."""
9595
//| ...
9696
//|
@@ -107,13 +107,13 @@ STATIC void check_for_deinit(bitbangio_spi_obj_t *self) {
107107
}
108108
}
109109

110-
//| def __enter__(self, ) -> Any:
110+
//| def __enter__(self, ) -> SPI:
111111
//| """No-op used by Context Managers."""
112112
//| ...
113113
//|
114114
// Provided by context manager helper.
115115

116-
//| def __exit__(self, ) -> Any:
116+
//| def __exit__(self, ) -> None:
117117
//| """Automatically deinitializes the hardware when exiting a context. See
118118
//| :ref:`lifetime-and-contextmanagers` for more info."""
119119
//| ...
@@ -132,7 +132,7 @@ static void check_lock(bitbangio_spi_obj_t *self) {
132132
}
133133
}
134134

135-
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
135+
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> None:
136136
//| """Configures the SPI bus. Only valid when locked.
137137
//|
138138
//| :param int baudrate: the clock rate in Hertz
@@ -174,7 +174,7 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args,
174174
}
175175
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configure);
176176

177-
//| def try_lock(self, ) -> Any:
177+
//| def try_lock(self, ) -> bool:
178178
//| """Attempts to grab the SPI lock. Returns True on success.
179179
//|
180180
//| :return: True when lock has been grabbed
@@ -188,7 +188,7 @@ STATIC mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) {
188188
}
189189
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock);
190190

191-
//| def unlock(self, ) -> Any:
191+
//| def unlock(self, ) -> None:
192192
//| """Releases the SPI lock."""
193193
//| ...
194194
//|
@@ -200,7 +200,7 @@ STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) {
200200
}
201201
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock);
202202

203-
//| def write(self, buf: Any) -> Any:
203+
//| def write(self, buf: bytes) -> None:
204204
//| """Write the data contained in ``buf``. Requires the SPI being locked.
205205
//| If the buffer is empty, nothing happens."""
206206
//| ...
@@ -224,7 +224,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
224224
MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write);
225225

226226

227-
//| def readinto(self, buf: Any) -> Any:
227+
//| def readinto(self, buf: bytearray) -> None:
228228
//| """Read into the buffer specified by ``buf`` while writing zeroes.
229229
//| Requires the SPI being locked.
230230
//| If the number of bytes to read is 0, nothing happens."""
@@ -248,7 +248,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
248248
}
249249
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto);
250250

251-
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
251+
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None:
252252
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
253253
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
254254
//| must be equal.

0 commit comments

Comments
 (0)