Skip to content

resolves #8 Missing 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 4 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions adafruit_ble_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
from adafruit_ble.uuid import VendorUUID
from adafruit_ble.services import Service

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

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI.git"

Expand All @@ -30,7 +35,7 @@ class _MidiCharacteristic(ComplexCharacteristic):

uuid = VendorUUID("7772E5DB-3868-4112-A1A9-F2669D106BF3")

def __init__(self):
def __init__(self) -> None:
super().__init__(
properties=Characteristic.WRITE_NO_RESPONSE
| Characteristic.READ
Expand All @@ -41,7 +46,7 @@ def __init__(self):
fixed_length=False,
)

def bind(self, service):
def bind(self, service: Service) -> _bleio.PacketBuffer:
"""Binds the characteristic to the given Service."""
bound_characteristic = super().bind(service)
return _bleio.PacketBuffer(bound_characteristic, buffer_size=4)
Expand All @@ -60,7 +65,7 @@ class MIDIService(Service):
# so it complains about missing members.
# pylint: disable=no-member

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
# Defer creating _in_buffer until we're definitely connected.
self._in_buffer = None
Expand All @@ -82,7 +87,7 @@ def __init__(self, **kwargs):
self._in_index = 1
self._last_data = True

def readinto(self, buf, length):
def readinto(self, buf: WriteableBuffer, length: int) -> int:
"""Reads up to ``length`` bytes into ``buf`` starting at index 0.

Returns the number of bytes written into ``buf``."""
Expand Down Expand Up @@ -115,13 +120,13 @@ def readinto(self, buf, length):

return i

def read(self, length):
def read(self, length: int) -> bytearray:
"""Reads up to ``length`` bytes and returns them."""
result = bytearray(length)
i = self.readinto(result, length)
return result[:i]

def write(self, buf, length):
def write(self, buf: ReadableBuffer, length: int) -> None:
"""Writes ``length`` bytes out."""
# pylint: disable=too-many-branches
timestamp_ms = time.monotonic_ns() // 1000000
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-ble
adafruit-circuitpython-typing