Skip to content

Commit 6319059

Browse files
authored
Merge pull request #10 from tcfranks/main
resolves #8 Missing Type Annotations
2 parents d5f7cfe + 8451d8b commit 6319059

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

adafruit_ble_midi.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
from adafruit_ble.uuid import VendorUUID
2020
from adafruit_ble.services import Service
2121

22+
try:
23+
import typing # pylint: disable=unused-import
24+
from circuitpython_typing import WriteableBuffer, ReadableBuffer
25+
except ImportError:
26+
pass
27+
2228
__version__ = "0.0.0+auto.0"
2329
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI.git"
2430

@@ -30,7 +36,7 @@ class _MidiCharacteristic(ComplexCharacteristic):
3036

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

33-
def __init__(self):
39+
def __init__(self) -> None:
3440
super().__init__(
3541
properties=Characteristic.WRITE_NO_RESPONSE
3642
| Characteristic.READ
@@ -41,7 +47,7 @@ def __init__(self):
4147
fixed_length=False,
4248
)
4349

44-
def bind(self, service):
50+
def bind(self, service: "MIDIService") -> _bleio.PacketBuffer:
4551
"""Binds the characteristic to the given Service."""
4652
bound_characteristic = super().bind(service)
4753
return _bleio.PacketBuffer(bound_characteristic, buffer_size=4)
@@ -60,7 +66,7 @@ class MIDIService(Service):
6066
# so it complains about missing members.
6167
# pylint: disable=no-member
6268

63-
def __init__(self, **kwargs):
69+
def __init__(self, **kwargs) -> None:
6470
super().__init__(**kwargs)
6571
# Defer creating _in_buffer until we're definitely connected.
6672
self._in_buffer = None
@@ -82,7 +88,7 @@ def __init__(self, **kwargs):
8288
self._in_index = 1
8389
self._last_data = True
8490

85-
def readinto(self, buf, length):
91+
def readinto(self, buf: WriteableBuffer, length: int) -> int:
8692
"""Reads up to ``length`` bytes into ``buf`` starting at index 0.
8793
8894
Returns the number of bytes written into ``buf``."""
@@ -115,13 +121,13 @@ def readinto(self, buf, length):
115121

116122
return i
117123

118-
def read(self, length):
124+
def read(self, length: int) -> bytearray:
119125
"""Reads up to ``length`` bytes and returns them."""
120126
result = bytearray(length)
121127
i = self.readinto(result, length)
122128
return result[:i]
123129

124-
def write(self, buf, length):
130+
def write(self, buf: ReadableBuffer, length: int) -> None:
125131
"""Writes ``length`` bytes out."""
126132
# pylint: disable=too-many-branches
127133
timestamp_ms = time.monotonic_ns() // 1000000

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
Adafruit-Blinka
66
adafruit-circuitpython-ble
7+
adafruit-circuitpython-typing

0 commit comments

Comments
 (0)