Skip to content

Fix type annotations #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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