14
14
__version__ = "0.0.0-auto.0"
15
15
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"
16
16
17
-
17
+ import array
18
18
from typing import Union , Optional
19
19
20
20
# Protocol was introduced in Python 3.8.
21
21
try :
22
- from typing import Protocol
22
+ from typing import Protocol # pylint: disable=ungrouped-imports
23
23
except ImportError :
24
24
from typing_extensions import Protocol
25
25
26
- from array import array
26
+ # Lists below are alphabetized.
27
27
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
+ ]
35
37
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."""
42
56
43
57
44
58
class ByteStream (Protocol ):
@@ -63,3 +77,25 @@ def read(self, count: Optional[int] = None) -> Optional[bytes]:
63
77
def write (self , buf : ReadableBuffer ) -> Optional [int ]:
64
78
"""Write the bytes in ``buf`` to the stream."""
65
79
...
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