Skip to content

Commit 6348879

Browse files
authored
Merge pull request #45 from dhalbert/fix-end-values
Fix default end values.
2 parents 2d90646 + edd71b8 commit 6348879

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_bus_device/i2c_device.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ def readinto(self, buf, *, start=0, end=None):
7878
7979
:param bytearray buffer: buffer to write into
8080
:param int start: Index to start writing at
81-
:param int end: Index to write up to but not include
81+
:param int end: Index to write up to but not include; if None, use ``len(buf)``
8282
"""
83+
if end is None:
84+
end = len(buf)
8385
self.i2c.readfrom_into(self.device_address, buf, start=start, end=end)
8486

8587
def write(self, buf, *, start=0, end=None, stop=True):
@@ -93,9 +95,11 @@ def write(self, buf, *, start=0, end=None, stop=True):
9395
9496
:param bytearray buffer: buffer containing the bytes to write
9597
:param int start: Index to start writing from
96-
:param int end: Index to read up to but not include
98+
:param int end: Index to read up to but not include; if None, use ``len(buf)``
9799
:param bool stop: If true, output an I2C stop condition after the buffer is written
98100
"""
101+
if end is None:
102+
end = len(buf)
99103
self.i2c.writeto(self.device_address, buf, start=start, end=end, stop=stop)
100104

101105
#pylint: disable-msg=too-many-arguments
@@ -119,9 +123,9 @@ def write_then_readinto(self, out_buffer, in_buffer, *,
119123
:param bytearray out_buffer: buffer containing the bytes to write
120124
:param bytearray in_buffer: buffer containing the bytes to read into
121125
:param int out_start: Index to start writing from
122-
:param int out_end: Index to read up to but not include
126+
:param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
123127
:param int in_start: Index to start writing at
124-
:param int in_end: Index to write up to but not include
128+
:param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
125129
:param bool stop: Deprecated
126130
"""
127131
if out_end is None:

0 commit comments

Comments
 (0)