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
Changes from 1 commit
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 @@ -10,11 +10,15 @@
This module provides Services used by MicroChip

"""

from adafruit_ble import Service
from adafruit_ble.uuid import VendorUUID
from adafruit_ble.characteristics.stream import StreamOut, StreamIn

try:
from typing import Union
except ImportError:
pass

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

def __init__(self, service=None):
def __init__(self, service: Union[Service, None] = None):
super().__init__(service=service)
self.connectable = True
if not service:
Expand All @@ -55,7 +59,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: Union[bytes, None] = None) -> Union[bytes, None]:
"""
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 +70,9 @@ def read(self, nbytes=None):
"""
return self._rx.read(nbytes)

def readinto(self, buf, nbytes=None):
def readinto(
self, buf: bytes, nbytes: Union[bytes, None] = None
) -> Union[int, None]:
"""
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 +82,7 @@ def readinto(self, buf, nbytes=None):
"""
return self._rx.readinto(buf, nbytes)

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

Expand All @@ -86,14 +92,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: bytes) -> None:
"""Write a buffer of bytes."""
self._tx.write(buf)