Skip to content

Commit b48bb75

Browse files
committed
change len(buffer) to sys.maxsize; must import sys
1 parent 1acafbf commit b48bb75

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

shared-bindings/adafruit_bus_device/I2CDevice.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const
109109
}
110110
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit___obj, 4, 4, adafruit_bus_device_i2cdevice_obj___exit__);
111111

112-
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = len(buffer)) -> None:
112+
//| import sys
113+
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
113114
//| """Read into ``buffer`` from the device. The number of bytes read will be the
114115
//| length of ``buffer``.
115116
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
@@ -154,7 +155,8 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_o
154155
}
155156
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 1, adafruit_bus_device_i2cdevice_readinto);
156157

157-
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = len(buffer)) -> None:
158+
//| import sys
159+
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
158160
//| """Write the bytes from ``buffer`` to the device, then transmit a stop bit.
159161
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
160162
//| as if ``buffer[start:end]``. This will not cause an allocation like
@@ -199,7 +201,8 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_
199201
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_bus_device_i2cdevice_write);
200202

201203

202-
//| def write_then_readinto(self, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = len(out_buffer), in_start: int = 0, in_end: int = len(in_buffer)) -> None:
204+
//| import sys
205+
//| def write_then_readinto(self, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
203206
//| """Write the bytes from ``out_buffer`` to the device, then immediately
204207
//| reads into ``in_buffer`` from the device. The number of bytes read
205208
//| will be the length of ``in_buffer``.
@@ -215,9 +218,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_
215218
//| :param bytearray out_buffer: buffer containing the bytes to write
216219
//| :param bytearray in_buffer: buffer containing the bytes to read into
217220
//| :param int out_start: Index to start writing from
218-
//| :param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
221+
//| :param int out_end: Index to read up to but not include; if not specified, use ``len(out_buffer)``
219222
//| :param int in_start: Index to start writing at
220-
//| :param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
223+
//| :param int in_end: Index to write up to but not include; if not specified, use ``len(in_buffer)``
221224
//| """
222225
//| ...
223226
//|

shared-bindings/bitbangio/I2C.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ 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: WriteableBuffer, *, start: int = 0, end: int = len(buffer)) -> None:
168+
//| import sys
169+
//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
169170
//| """Read into ``buffer`` from the device selected by ``address``.
170171
//| The number of bytes read will be the length of ``buffer``.
171172
//| At least one byte must be read.
@@ -217,7 +218,8 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
217218
}
218219
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 1, bitbangio_i2c_readfrom_into);
219220

220-
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
221+
//| import sys
222+
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
221223
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a
222224
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
223225
//| before a read.
@@ -232,7 +234,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 1, bitbangio_i2c_rea
232234
//| :param int address: 7-bit device address
233235
//| :param ~_typing.ReadableBuffer buffer: buffer containing the bytes to write
234236
//| :param int start: Index to start writing from
235-
//| :param int end: Index to read up to but not include"""
237+
//| :param int end: Index to read up to but not include. If not specified, use ``len(buffer)``"""
236238
//| ...
237239
//|
238240
// Shared arg parsing for writeto and writeto_then_readfrom.
@@ -274,7 +276,8 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
274276
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto);
275277

276278

277-
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = len(out_buffer), in_start: int = 0, in_end: int = len(in_buffer)) -> None:
279+
//| import sys
280+
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
278281
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
279282
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
280283
//| ``in_buffer`` can be the same buffer because they are used sequentially.
@@ -287,9 +290,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr
287290
//| :param ~_typing.ReadableBuffer out_buffer: buffer containing the bytes to write
288291
//| :param ~_typing.WriteableBuffer in_buffer: buffer to write into
289292
//| :param int out_start: Index to start writing from
290-
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
293+
//| :param int out_end: Index to read up to but not include. If not specified, use ``len(buffer)``
291294
//| :param int in_start: Index to start writing at
292-
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
295+
//| :param int in_end: Index to write up to but not include. If not specified, use ``len(buffer)``"""
293296
//|
294297
STATIC mp_obj_t bitbangio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
295298
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };

shared-bindings/bitbangio/SPI.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,15 @@ 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, buffer: WriteableBuffer, *, start: int = 0, end: int = len(buffer), write_value: int = 0) -> None:
227+
//| import sys
228+
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize, write_value: int = 0) -> None:
228229
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
229230
//| The SPI object must be locked.
230231
//| If the number of bytes to read is 0, nothing happens.
231232
//|
232233
//| :param bytearray buffer: Read data into this buffer
233234
//| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
234-
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
235+
//| :param int end: End of the slice; this index is not included. If not specified, use ``len(buffer)``
235236
//| :param int write_value: Value to write while reading."""
236237
//| ...
237238
//|
@@ -268,7 +269,8 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *pos_args,
268269
}
269270
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_readinto_obj, 1, bitbangio_spi_readinto);
270271

271-
//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: ReadableBuffer, *, out_start: int = 0, out_end: int = len(buffer_out), in_start: int = 0, in_end: int = len(buffer_in)) -> None:
272+
//| import sys
273+
//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: ReadableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
272274
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
273275
//| The SPI object must be locked.
274276
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
@@ -278,9 +280,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_readinto_obj, 1, bitbangio_spi_readinto
278280
//| :param ~_typing.ReadableBuffer buffer_out: Write out the data in this buffer
279281
//| :param ~_typing.WriteableBuffer buffer_in: Read data into this buffer
280282
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
281-
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
283+
//| :param int out_end: End of the slice; this index is not included. If not specified, use ``len(buffer_out)``
282284
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
283-
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
285+
//| :param int in_end: End of the slice; this index is not included. If not specified, use ``len(buffer_in)``"""
284286
//| ...
285287
//|
286288
STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

shared-bindings/busio/I2C.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
176176
}
177177
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
178178

179-
//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
179+
//| import sys
180+
//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
180181
//| """Read into ``buffer`` from the device selected by ``address``.
181182
//| The number of bytes read will be the length of ``buffer``.
182183
//| At least one byte must be read.
@@ -188,7 +189,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
188189
//| :param int address: 7-bit device address
189190
//| :param ~_typing.WriteableBuffer buffer: buffer to write into
190191
//| :param int start: Index to start writing at
191-
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
192+
//| :param int end: Index to write up to but not include. If not specified, use ``len(buffer)``"""
192193
//| ...
193194
//|
194195
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
@@ -228,7 +229,8 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args,
228229
}
229230
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 1, busio_i2c_readfrom_into);
230231

231-
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
232+
//| import sys
233+
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
232234
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and
233235
//| then transmit a stop bit.
234236
//|
@@ -242,7 +244,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 1, busio_i2c_readfrom_in
242244
//| :param int address: 7-bit device address
243245
//| :param ~_typing.ReadableBuffer buffer: buffer containing the bytes to write
244246
//| :param int start: Index to start writing from
245-
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``"""
247+
//| :param int end: Index to read up to but not include. If not specified, use ``len(buffer)``"""
246248
//| ...
247249
//|
248250
// Shared arg parsing for writeto and writeto_then_readfrom.
@@ -282,7 +284,8 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
282284
}
283285
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
284286

285-
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: WriteableBuffer, *, out_start: int = 0, out_end: Optional[int] = None, in_start: int = 0, in_end: Optional[int] = None) -> None:
287+
//| import sys
288+
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: WriteableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
286289
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
287290
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
288291
//| ``in_buffer`` can be the same buffer because they are used sequentially.
@@ -295,9 +298,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
295298
//| :param ~_typing.ReadableBuffer out_buffer: buffer containing the bytes to write
296299
//| :param ~_typing.WriteableBuffer in_buffer: buffer to write into
297300
//| :param int out_start: Index to start writing from
298-
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
301+
//| :param int out_end: Index to read up to but not include. If not specified, use ``len(buffer)``
299302
//| :param int in_start: Index to start writing at
300-
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
303+
//| :param int in_end: Index to write up to but not include. If not specified, use ``len(buffer)``"""
301304
//| ...
302305
//|
303306
STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {

shared-bindings/busio/SPI.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) {
237237
}
238238
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock);
239239

240-
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = len(buffer)) -> None:
240+
//| import sys
241+
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
241242
//| """Write the data contained in ``buffer``. The SPI object must be locked.
242243
//| If the buffer is empty, nothing happens.
243244
//|
@@ -279,7 +280,8 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
279280
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 1, busio_spi_write);
280281

281282

282-
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = len(buffer), write_value: int = 0) -> None:
283+
//| import sys
284+
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize, write_value: int = 0) -> None:
283285
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
284286
//| The SPI object must be locked.
285287
//| If the number of bytes to read is 0, nothing happens.
@@ -323,7 +325,8 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
323325
}
324326
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 1, busio_spi_readinto);
325327

326-
//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: WriteableBuffer, *, out_start: int = 0, out_end: int = len(buffer_out), in_start: int = 0, in_end: int = len(buffer_in)) -> None:
328+
//| import sys
329+
//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: WriteableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
327330
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
328331
//| The SPI object must be locked.
329332
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
@@ -333,9 +336,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 1, busio_spi_readinto);
333336
//| :param ~_typing.ReadableBuffer buffer_out: Write out the data in this buffer
334337
//| :param ~_typing.WriteableBuffer buffer_in: Read data into this buffer
335338
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
336-
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
339+
//| :param int out_end: End of the slice; this index is not included. If not specified, use ``len(buffer_out)``
337340
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
338-
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
341+
//| :param int in_end: End of the slice; this index is not included. If not specified, use ``len(buffer_in)``"""
339342
//| ...
340343
//|
341344

0 commit comments

Comments
 (0)