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
0 commit comments