27
27
import adafruit_pypixelbuf as adafruit_pixelbuf
28
28
29
29
30
+ try :
31
+ # Used only for typing
32
+ from typing import Optional , Type
33
+ from types import TracebackType
34
+ import microcontroller
35
+ except ImportError :
36
+ pass
37
+
38
+
30
39
__version__ = "0.0.0-auto.0"
31
40
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel.git"
32
41
@@ -102,7 +111,14 @@ class NeoPixel(adafruit_pixelbuf.PixelBuf):
102
111
"""
103
112
104
113
def __init__ (
105
- self , pin , n , * , bpp = 3 , brightness = 1.0 , auto_write = True , pixel_order = None
114
+ self ,
115
+ pin : microcontroller .Pin ,
116
+ n : int ,
117
+ * ,
118
+ bpp : int = 3 ,
119
+ brightness : float = 1.0 ,
120
+ auto_write : bool = True ,
121
+ pixel_order : str = None
106
122
):
107
123
if not pixel_order :
108
124
pixel_order = GRB if bpp == 3 else GRBW
@@ -133,7 +149,7 @@ def __init__(
133
149
self .pin = digitalio .DigitalInOut (pin )
134
150
self .pin .direction = digitalio .Direction .OUTPUT
135
151
136
- def deinit (self ):
152
+ def deinit (self ) -> None :
137
153
"""Blank out the NeoPixels and release the pin."""
138
154
self .fill (0 )
139
155
self .show ()
@@ -144,24 +160,29 @@ def deinit(self):
144
160
def __enter__ (self ):
145
161
return self
146
162
147
- def __exit__ (self , exception_type , exception_value , traceback ):
163
+ def __exit__ (
164
+ self ,
165
+ exception_type : Optional [Type [BaseException ]],
166
+ exception_value : Optional [BaseException ],
167
+ traceback : Optional [TracebackType ],
168
+ ):
148
169
self .deinit ()
149
170
150
171
def __repr__ (self ):
151
172
return "[" + ", " .join ([str (x ) for x in self ]) + "]"
152
173
153
174
@property
154
- def n (self ):
175
+ def n (self ) -> int :
155
176
"""
156
177
The number of neopixels in the chain (read-only)
157
178
"""
158
179
return len (self )
159
180
160
- def write (self ):
181
+ def write (self ) -> None :
161
182
""".. deprecated: 1.0.0
162
183
163
184
Use ``show`` instead. It matches Micro:Bit and Arduino APIs."""
164
185
self .show ()
165
186
166
- def _transmit (self , buffer ) :
187
+ def _transmit (self , buffer : bytearray ) -> None :
167
188
neopixel_write (self .pin , buffer )
0 commit comments