Skip to content

Commit 159bf41

Browse files
committed
move defs shared-bindings/circuitpython_typing to here
1 parent 60e5346 commit 159bf41

File tree

4 files changed

+71
-16
lines changed

4 files changed

+71
-16
lines changed

circuitpython_typing/__init__.py

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,45 @@
1414
__version__ = "0.0.0-auto.0"
1515
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"
1616

17-
17+
import array
1818
from typing import Union, Optional
1919

2020
# Protocol was introduced in Python 3.8.
2121
try:
22-
from typing import Protocol
22+
from typing import Protocol # pylint: disable=ungrouped-imports
2323
except 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

4458
class 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+
"""

circuitpython_typing/py.typed

Whitespace-only changes.

circuitpython_typing/socket.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222

2323
# Based on https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi
2424

25+
__all__ = [
26+
# alphabetized
27+
"CircuitPythonSocketType",
28+
"CommonCircuitPythonSocketType",
29+
"CommonSocketType",
30+
"InterfaceType",
31+
"LegacyCircuitPythonSocketType",
32+
"SSLContextType",
33+
"SocketType",
34+
"SocketpoolModuleType",
35+
"StandardPythonSocketType",
36+
"SupportsRecvInto",
37+
"SupportsRecvWithFlags",
38+
]
39+
2540

2641
class CommonSocketType(Protocol):
2742
"""Describes the common structure every socket type must have."""

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@
5656
# You can just specify the packages manually here if your project is
5757
# simple. Or you can use find_packages().
5858
packages=["circuitpython_typing"],
59+
# Make the types available for mypy type checking. See PEP 561.
60+
package_data={
61+
"circuitpython_typing": ["py.typed"],
62+
},
5963
)

0 commit comments

Comments
 (0)