Skip to content

Commit 2ceb963

Browse files
authored
Merge pull request #28 from tekktrik/dev/fix-annotations
Fix type annotations
2 parents a46a0ff + ecd8841 commit 2ceb963

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

adafruit_onewire/bus.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
try:
2121
from typing import Optional, List, Tuple
22+
from circuitpython_typing import ReadableBuffer, WriteableBuffer
2223
from microcontroller import Pin
2324
except ImportError:
2425
pass
@@ -97,7 +98,7 @@ def reset(self, required: bool = False) -> bool:
9798
return not reset
9899

99100
def readinto(
100-
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
101+
self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None
101102
) -> None:
102103
"""
103104
Read into ``buf`` from the device. The number of bytes read will be the
@@ -107,7 +108,7 @@ def readinto(
107108
as if ``buf[start:end]``. This will not cause an allocation like
108109
``buf[start:end]`` will so it saves memory.
109110
110-
:param bytearray buf: buffer to write into
111+
:param ~WriteableBuffer buf: Buffer to write into
111112
:param int start: Index to start writing at
112113
:param int end: Index to write up to but not include
113114
"""
@@ -117,7 +118,7 @@ def readinto(
117118
buf[i] = self._readbyte()
118119

119120
def write(
120-
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
121+
self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None
121122
) -> None:
122123
"""
123124
Write the bytes from ``buf`` to the device.
@@ -126,7 +127,7 @@ def write(
126127
as if ``buffer[start:end]``. This will not cause an allocation like
127128
``buffer[start:end]`` will so it saves memory.
128129
129-
:param bytearray buf: buffer containing the bytes to write
130+
:param ReadableBuffer buf: Buffer containing the bytes to write
130131
:param int start: Index to start writing from
131132
:param int end: Index to read up to but not include
132133
"""
@@ -168,7 +169,7 @@ def _writebyte(self, value: int) -> None:
168169
self._ow.write_bit(bit)
169170

170171
def _search_rom(
171-
self, l_rom: Optional[bytearray], diff: int
172+
self, l_rom: Optional[ReadableBuffer], diff: int
172173
) -> Tuple[bytearray, int]:
173174
if not self.reset():
174175
return None, 0
@@ -197,11 +198,11 @@ def _search_rom(
197198
return rom, next_diff
198199

199200
@staticmethod
200-
def crc8(data: bytearray) -> int:
201+
def crc8(data: ReadableBuffer) -> int:
201202
"""
202203
Perform the 1-Wire CRC check on the provided data.
203204
204-
:param bytearray data: 8 byte array representing 64 bit ROM code
205+
:param ReadableBuffer data: 8 byte array representing 64 bit ROM code
205206
"""
206207
crc = 0
207208

adafruit_onewire/device.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
try:
1818
from typing import Optional, Type
19+
from circuitpython_typing import ReadableBuffer, WriteableBuffer
1920
from types import TracebackType
2021
from adafruit_onewire.bus import OneWireBus, OneWireAddress
2122
except ImportError:
@@ -44,7 +45,7 @@ def __exit__(
4445
return False
4546

4647
def readinto(
47-
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
48+
self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None
4849
) -> None:
4950
"""
5051
Read into ``buf`` from the device. The number of bytes read will be the
@@ -54,7 +55,7 @@ def readinto(
5455
as if ``buf[start:end]``. This will not cause an allocation like
5556
``buf[start:end]`` will so it saves memory.
5657
57-
:param bytearray buf: buffer to write into
58+
:param WriteableBuffer buf: Buffer to write into
5859
:param int start: Index to start writing at
5960
:param int end: Index to write up to but not include
6061
"""
@@ -64,7 +65,7 @@ def readinto(
6465
raise RuntimeError("CRC error.")
6566

6667
def write(
67-
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
68+
self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None
6869
) -> None:
6970
"""
7071
Write the bytes from ``buf`` to the device.
@@ -73,7 +74,7 @@ def write(
7374
as if ``buffer[start:end]``. This will not cause an allocation like
7475
``buffer[start:end]`` will so it saves memory.
7576
76-
:param bytearray buf: buffer containing the bytes to write
77+
:param ReadableBuffer buf: buffer containing the bytes to write
7778
:param int start: Index to start writing from
7879
:param int end: Index to read up to but not include
7980
"""

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
Adafruit-Blinka
66
adafruit-circuitpython-busdevice
7+
adafruit-circuitpython-typing

0 commit comments

Comments
 (0)