Skip to content

Commit

Permalink
Merge pull request #28 from tekktrik/dev/fix-annotations
Browse files Browse the repository at this point in the history
Fix type annotations
  • Loading branch information
dhalbert committed Jan 11, 2023
2 parents a46a0ff + ecd8841 commit 2ceb963
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions adafruit_onewire/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

try:
from typing import Optional, List, Tuple
from circuitpython_typing import ReadableBuffer, WriteableBuffer
from microcontroller import Pin
except ImportError:
pass
Expand Down Expand Up @@ -97,7 +98,7 @@ def reset(self, required: bool = False) -> bool:
return not reset

def readinto(
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None
) -> None:
"""
Read into ``buf`` from the device. The number of bytes read will be the
Expand All @@ -107,7 +108,7 @@ def readinto(
as if ``buf[start:end]``. This will not cause an allocation like
``buf[start:end]`` will so it saves memory.
:param bytearray buf: buffer to write into
:param ~WriteableBuffer buf: Buffer to write into
:param int start: Index to start writing at
:param int end: Index to write up to but not include
"""
Expand All @@ -117,7 +118,7 @@ def readinto(
buf[i] = self._readbyte()

def write(
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None
) -> None:
"""
Write the bytes from ``buf`` to the device.
Expand All @@ -126,7 +127,7 @@ def write(
as if ``buffer[start:end]``. This will not cause an allocation like
``buffer[start:end]`` will so it saves memory.
:param bytearray buf: buffer containing the bytes to write
:param ReadableBuffer buf: 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
"""
Expand Down Expand Up @@ -168,7 +169,7 @@ def _writebyte(self, value: int) -> None:
self._ow.write_bit(bit)

def _search_rom(
self, l_rom: Optional[bytearray], diff: int
self, l_rom: Optional[ReadableBuffer], diff: int
) -> Tuple[bytearray, int]:
if not self.reset():
return None, 0
Expand Down Expand Up @@ -197,11 +198,11 @@ def _search_rom(
return rom, next_diff

@staticmethod
def crc8(data: bytearray) -> int:
def crc8(data: ReadableBuffer) -> int:
"""
Perform the 1-Wire CRC check on the provided data.
:param bytearray data: 8 byte array representing 64 bit ROM code
:param ReadableBuffer data: 8 byte array representing 64 bit ROM code
"""
crc = 0

Expand Down
9 changes: 5 additions & 4 deletions adafruit_onewire/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

try:
from typing import Optional, Type
from circuitpython_typing import ReadableBuffer, WriteableBuffer
from types import TracebackType
from adafruit_onewire.bus import OneWireBus, OneWireAddress
except ImportError:
Expand Down Expand Up @@ -44,7 +45,7 @@ def __exit__(
return False

def readinto(
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None
) -> None:
"""
Read into ``buf`` from the device. The number of bytes read will be the
Expand All @@ -54,7 +55,7 @@ def readinto(
as if ``buf[start:end]``. This will not cause an allocation like
``buf[start:end]`` will so it saves memory.
:param bytearray buf: buffer to write into
:param WriteableBuffer buf: Buffer to write into
:param int start: Index to start writing at
:param int end: Index to write up to but not include
"""
Expand All @@ -64,7 +65,7 @@ def readinto(
raise RuntimeError("CRC error.")

def write(
self, buf: bytearray, *, start: int = 0, end: Optional[int] = None
self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None
) -> None:
"""
Write the bytes from ``buf`` to the device.
Expand All @@ -73,7 +74,7 @@ def write(
as if ``buffer[start:end]``. This will not cause an allocation like
``buffer[start:end]`` will so it saves memory.
:param bytearray buf: buffer containing the bytes to write
:param ReadableBuffer buf: 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
"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

Adafruit-Blinka
adafruit-circuitpython-busdevice
adafruit-circuitpython-typing

0 comments on commit 2ceb963

Please sign in to comment.