From edd71b8c314b67bb3a4010943f4ee82ed9f6a289 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 18 Feb 2020 20:22:26 -0500 Subject: [PATCH] Fix default end values. --- adafruit_bus_device/i2c_device.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/adafruit_bus_device/i2c_device.py b/adafruit_bus_device/i2c_device.py index 546069e..4261a10 100644 --- a/adafruit_bus_device/i2c_device.py +++ b/adafruit_bus_device/i2c_device.py @@ -78,8 +78,10 @@ def readinto(self, buf, *, start=0, end=None): :param bytearray buffer: buffer to write into :param int start: Index to start writing at - :param int end: Index to write up to but not include + :param int end: Index to write up to but not include; if None, use ``len(buf)`` """ + if end is None: + end = len(buf) self.i2c.readfrom_into(self.device_address, buf, start=start, end=end) def write(self, buf, *, start=0, end=None, stop=True): @@ -93,9 +95,11 @@ def write(self, buf, *, start=0, end=None, stop=True): :param bytearray buffer: buffer containing the bytes to write :param int start: Index to start writing from - :param int end: Index to read up to but not include + :param int end: Index to read up to but not include; if None, use ``len(buf)`` :param bool stop: If true, output an I2C stop condition after the buffer is written """ + if end is None: + end = len(buf) self.i2c.writeto(self.device_address, buf, start=start, end=end, stop=stop) #pylint: disable-msg=too-many-arguments @@ -119,9 +123,9 @@ def write_then_readinto(self, out_buffer, in_buffer, *, :param bytearray out_buffer: buffer containing the bytes to write :param bytearray in_buffer: buffer containing the bytes to read into :param int out_start: Index to start writing from - :param int out_end: Index to read up to but not include + :param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)`` :param int in_start: Index to start writing at - :param int in_end: Index to write up to but not include + :param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)`` :param bool stop: Deprecated """ if out_end is None: