1414__version__ = "0.0.0-auto.0"
1515__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"
1616
17-
17+ import array
1818from typing import Union , Optional
1919
2020# Protocol was introduced in Python 3.8.
2121try :
22- from typing import Protocol
22+ from typing import Protocol # pylint: disable=ungrouped-imports
2323except ImportError :
2424 from typing_extensions import Protocol
2525
26- from array import array
26+ # Lists below are alphabetized.
2727
28- ReadableBuffer = Union [bytes , bytearray , memoryview , array ]
29- """Classes that implement the readable buffer protocol
30- * `bytes`
31- * `bytearray`
32- * `memoryview`
33- * `array.array`
34- """
28+ # More added in each conditional import.
29+ __all__ = [
30+ "Alarm" ,
31+ "AudioSample" ,
32+ "ByteStream" ,
33+ "FrameBuffer" ,
34+ "ReadableBuffer" ,
35+ "WriteableBuffer" ,
36+ ]
3537
36- WriteableBuffer = Union [bytearray , memoryview , array ]
37- """Classes that implement the writeable buffer protocol
38- * `bytearray`
39- * `memoryview`
40- * `array.array`
41- """
38+ ReadableBuffer = Union [
39+ array .array ,
40+ bytearray ,
41+ bytes ,
42+ memoryview ,
43+ "rgbmatrix.RGBMatrix" ,
44+ "ulab.numpy.ndarray" ,
45+ ]
46+ """Classes that implement the readable buffer protocol."""
47+
48+ WriteableBuffer = Union [
49+ array .array ,
50+ bytearray ,
51+ memoryview ,
52+ "rgbmatrix.RGBMatrix" ,
53+ "ulab.numpy.ndarray" ,
54+ ]
55+ """Classes that implement the writeable buffer protocol."""
4256
4357
4458class ByteStream (Protocol ):
@@ -63,3 +77,25 @@ def read(self, count: Optional[int] = None) -> Optional[bytes]:
6377 def write (self , buf : ReadableBuffer ) -> Optional [int ]:
6478 """Write the bytes in ``buf`` to the stream."""
6579 ...
80+
81+
82+ # These types may not be in adafruit-blinka, so use the string form instead of a resolved name.
83+
84+ AudioSample = Union [
85+ "audiocore.WaveFile" ,
86+ "audiocore.RawSample" ,
87+ "audiomixer.Mixer" ,
88+ "audiomp3.MP3Decoder" ,
89+ "synthio.MidiTrack" ,
90+ ]
91+ """Classes that implement the audiosample protocol.
92+ You can play these back with `audioio.AudioOut`, `audiobusio.I2SOut` or `audiopwmio.PWMAudioOut`.
93+ """
94+
95+ FrameBuffer = Union ["rgbmatrix.RGBMatrix" ]
96+ """Classes that implement the framebuffer protocol."""
97+
98+ Alarm = Union ["alarm.pin.PinAlarm" , "alarm.time.TimeAlarm" ]
99+ """Classes that implement alarms for sleeping and asynchronous notification.
100+ You can use these alarms to wake up from light or deep sleep.
101+ """
0 commit comments