2727 import adafruit_pypixelbuf as adafruit_pixelbuf
2828
2929
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+
3039__version__ = "0.0.0-auto.0"
3140__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel.git"
3241
@@ -102,7 +111,14 @@ class NeoPixel(adafruit_pixelbuf.PixelBuf):
102111 """
103112
104113 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
106122 ):
107123 if not pixel_order :
108124 pixel_order = GRB if bpp == 3 else GRBW
@@ -133,7 +149,7 @@ def __init__(
133149 self .pin = digitalio .DigitalInOut (pin )
134150 self .pin .direction = digitalio .Direction .OUTPUT
135151
136- def deinit (self ):
152+ def deinit (self ) -> None :
137153 """Blank out the NeoPixels and release the pin."""
138154 self .fill (0 )
139155 self .show ()
@@ -144,24 +160,29 @@ def deinit(self):
144160 def __enter__ (self ):
145161 return self
146162
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+ ):
148169 self .deinit ()
149170
150171 def __repr__ (self ):
151172 return "[" + ", " .join ([str (x ) for x in self ]) + "]"
152173
153174 @property
154- def n (self ):
175+ def n (self ) -> int :
155176 """
156177 The number of neopixels in the chain (read-only)
157178 """
158179 return len (self )
159180
160- def write (self ):
181+ def write (self ) -> None :
161182 """.. deprecated: 1.0.0
162183
163184 Use ``show`` instead. It matches Micro:Bit and Arduino APIs."""
164185 self .show ()
165186
166- def _transmit (self , buffer ) :
187+ def _transmit (self , buffer : bytearray ) -> None :
167188 neopixel_write (self .pin , buffer )
0 commit comments