Skip to content

Commit fabe0e9

Browse files
committed
Add type hints
1 parent 202f929 commit fabe0e9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

neopixel.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
import adafruit_pypixelbuf as adafruit_pixelbuf
2828

2929

30+
try:
31+
from typing import Optional, Type
32+
from types import TracebackType
33+
except ImportError:
34+
pass
35+
36+
37+
import microcontroller
38+
39+
3040
__version__ = "0.0.0-auto.0"
3141
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel.git"
3242

@@ -102,7 +112,14 @@ class NeoPixel(adafruit_pixelbuf.PixelBuf):
102112
"""
103113

104114
def __init__(
105-
self, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None
115+
self,
116+
pin: microcontroller.Pin,
117+
n: int,
118+
*,
119+
bpp: int = 3,
120+
brightness: float = 1.0,
121+
auto_write: bool = True,
122+
pixel_order: str = None
106123
):
107124
if not pixel_order:
108125
pixel_order = GRB if bpp == 3 else GRBW
@@ -144,7 +161,12 @@ def deinit(self):
144161
def __enter__(self):
145162
return self
146163

147-
def __exit__(self, exception_type, exception_value, traceback):
164+
def __exit__(
165+
self,
166+
exception_type: Optional[Type[BaseException]],
167+
exception_value: Optional[BaseException],
168+
traceback: Optional[TracebackType],
169+
):
148170
self.deinit()
149171

150172
def __repr__(self):
@@ -163,5 +185,5 @@ def write(self):
163185
Use ``show`` instead. It matches Micro:Bit and Arduino APIs."""
164186
self.show()
165187

166-
def _transmit(self, buffer):
188+
def _transmit(self, buffer: bytearray):
167189
neopixel_write(self.pin, buffer)

0 commit comments

Comments
 (0)