Skip to content

add type annotations #10

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 3 commits into from
May 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
from adafruit_ble.uuid import VendorUUID
from adafruit_ble.characteristics.stream import StreamOut, StreamIn

try:
from typing import Optional
except ImportError:
pass
from circuitpython_typing import ReadableBuffer, WriteableBuffer

__version__ = "0.0.0-auto.0"
__repo__ = (
"https://github.com/adafruit/Adafruit_CircuitPython_BLE_Contec_Pulse_Oximeter.git"
Expand Down Expand Up @@ -44,7 +50,7 @@ class TransparentUARTService(Service):
buffer_size=64,
)

def __init__(self, service=None):
def __init__(self, service: Optional["TransparentUARTService"] = None):
super().__init__(service=service)
self.connectable = True
if not service:
Expand All @@ -55,7 +61,7 @@ def __init__(self, service=None):
self._tx = self._server_rx
self._rx = self._server_tx

def read(self, nbytes=None):
def read(self, nbytes: Optional[int] = None) -> Optional[bytes]:
"""
Read characters. If ``nbytes`` is specified then read at most that many bytes.
Otherwise, read everything that arrives until the connection times out.
Expand All @@ -66,7 +72,9 @@ def read(self, nbytes=None):
"""
return self._rx.read(nbytes)

def readinto(self, buf, nbytes=None):
def readinto(
self, buf: WriteableBuffer, nbytes: Optional[int] = None
) -> Optional[int]:
"""
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
that many bytes. Otherwise, read at most ``len(buf)`` bytes.
Expand All @@ -76,7 +84,7 @@ def readinto(self, buf, nbytes=None):
"""
return self._rx.readinto(buf, nbytes)

def readline(self):
def readline(self) -> Optional[bytes]:
"""
Read a line, ending in a newline character.

Expand All @@ -86,14 +94,14 @@ def readline(self):
return self._rx.readline()

@property
def in_waiting(self):
def in_waiting(self) -> int:
"""The number of bytes in the input buffer, available to be read."""
return self._rx.in_waiting

def reset_input_buffer(self):
def reset_input_buffer(self) -> None:
"""Discard any unread characters in the input buffer."""
self._rx.reset_input_buffer()

def write(self, buf):
def write(self, buf: ReadableBuffer) -> None:
"""Write a buffer of bytes."""
self._tx.write(buf)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#
# SPDX-License-Identifier: Unlicense

Adafruit-Blinka
Adafruit-Blinka>=7.2.3
adafruit-circuitpython-ble
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-ble"],
install_requires=["Adafruit-Blinka>=7.2.3", "adafruit-circuitpython-ble"],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down