Skip to content

Commit a313e87

Browse files
authored
Merge pull request #59 from tekktrik/doc/add-typing
Add type annotations
2 parents 8f20f73 + 9feda92 commit a313e87

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

adafruit_dotstar.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
except ImportError:
2525
import adafruit_pypixelbuf as adafruit_pixelbuf
2626

27+
try:
28+
from typing import Optional, Type
29+
from types import TracebackType
30+
from circuitpython_typing import ReadableBuffer
31+
from microcontroller import Pin
32+
except ImportError:
33+
pass
34+
2735
__version__ = "0.0.0-auto.0"
2836
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git"
2937

@@ -95,15 +103,15 @@ class DotStar(adafruit_pixelbuf.PixelBuf):
95103

96104
def __init__(
97105
self,
98-
clock,
99-
data,
100-
n,
106+
clock: Pin,
107+
data: Pin,
108+
n: int,
101109
*,
102-
brightness=1.0,
103-
auto_write=True,
104-
pixel_order=BGR,
105-
baudrate=4000000
106-
):
110+
brightness: float = 1.0,
111+
auto_write: bool = True,
112+
pixel_order: str = BGR,
113+
baudrate: int = 4000000
114+
) -> None:
107115
self._spi = None
108116
try:
109117
self._spi = busio.SPI(clock, MOSI=data)
@@ -137,7 +145,7 @@ def __init__(
137145
trailer=trailer,
138146
)
139147

140-
def deinit(self):
148+
def deinit(self) -> None:
141149
"""Blank out the DotStars and release the resources."""
142150
self.fill(0)
143151
self.show()
@@ -147,29 +155,34 @@ def deinit(self):
147155
self.dpin.deinit()
148156
self.cpin.deinit()
149157

150-
def __enter__(self):
158+
def __enter__(self) -> "DotStar":
151159
return self
152160

153-
def __exit__(self, exception_type, exception_value, traceback):
161+
def __exit__(
162+
self,
163+
exception_type: Optional[Type[type]],
164+
exception_value: Optional[BaseException],
165+
traceback: Optional[TracebackType],
166+
) -> None:
154167
self.deinit()
155168

156-
def __repr__(self):
169+
def __repr__(self) -> str:
157170
return "[" + ", ".join([str(x) for x in self]) + "]"
158171

159172
@property
160-
def n(self):
173+
def n(self) -> int:
161174
"""
162175
The number of dotstars in the chain (read-only)
163176
"""
164177
return len(self)
165178

166-
def _transmit(self, buffer):
179+
def _transmit(self, buffer: ReadableBuffer) -> None:
167180
if self._spi:
168181
self._spi.write(buffer)
169182
else:
170183
self._ds_writebytes(buffer)
171184

172-
def _ds_writebytes(self, buffer):
185+
def _ds_writebytes(self, buffer: ReadableBuffer) -> None:
173186
for b in buffer:
174187
for _ in range(8):
175188
self.dpin.value = b & 0x80

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44

5-
Adafruit-Blinka
5+
Adafruit-Blinka>=7.0.0
6+
adafruit-circuitpython-typing
67
adafruit-circuitpython-busdevice
78
adafruit-circuitpython-pixelbuf

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
author="Adafruit Industries",
3636
author_email="circuitpython@adafruit.com",
3737
install_requires=[
38-
"Adafruit-Blinka",
38+
"Adafruit-Blinka>=7.0.0",
39+
"adafruit-circuitpython-typing",
3940
"adafruit-circuitpython-busdevice",
4041
"adafruit-circuitpython-pixelbuf",
4142
],

0 commit comments

Comments
 (0)