Skip to content

Commit c2af4be

Browse files
committed
typing tweaks
1 parent 72a3262 commit c2af4be

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

adafruit_is31fl3731/__init__.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class IS31FL3731:
111111
112112
:param ~busio.I2C i2c: the connected i2c bus i2c_device
113113
:param int address: the device address; defaults to 0x74
114-
:param int frames: static 0 or animation frames (0-7)
114+
:param Iterable frames: list of frame indexes to use. int's 0-7.
115115
"""
116116

117117
width: int = 16
@@ -120,14 +120,16 @@ class IS31FL3731:
120120
def __init__(
121121
self,
122122
i2c: busio.I2C,
123-
frames: Optional[int] = None,
123+
frames: Optional[Iterable] = None,
124124
address: int = 0x74,
125125
):
126126
self.i2c_device = I2CDevice(i2c, address)
127127
self._frame = None
128128
self._init(frames=frames)
129129

130-
def _i2c_read_reg(self, reg: Optional[int] = None, result: Optional[int] = None):
130+
def _i2c_read_reg(
131+
self, reg: Optional[int] = None, result: Optional[WriteableBuffer] = None
132+
) -> Optional[WriteableBuffer]:
131133
# Read a buffer of data from the specified 8-bit I2C register address.
132134
# The provided result parameter will be filled to capacity with bytes
133135
# of data read from the register.
@@ -190,13 +192,13 @@ def _init(self, frames: Iterable) -> None:
190192
self._frame = 0 # To match config bytes above
191193
self.sleep(False)
192194

193-
def reset(self):
195+
def reset(self) -> None:
194196
"""Kill the display for 10MS"""
195197
self.sleep(True)
196198
time.sleep(0.01) # 10 MS pause to reset.
197199
self.sleep(False)
198200

199-
def sleep(self, value):
201+
def sleep(self, value: bool) -> Optional[int]:
200202
"""
201203
Set the Software Shutdown Register bit
202204
@@ -206,10 +208,10 @@ def sleep(self, value):
206208

207209
def autoplay(
208210
self,
209-
delay: Optional[int] = None,
210-
loops: Optional[Iterable] = None,
211-
frames: Optional[int] = None,
212-
) -> int:
211+
delay: int = 0,
212+
loops: int = 0,
213+
frames: int = 0,
214+
) -> None:
213215
"""
214216
Start autoplay
215217
@@ -235,7 +237,7 @@ def fade(
235237
self,
236238
fade_in: Optional[int] = None,
237239
fade_out: Optional[int] = None,
238-
pause: Optional[int] = None,
240+
pause: int = 0,
239241
) -> int:
240242
"""
241243
Start and stop the fade feature. If both fade_in and fade_out are None (the
@@ -314,7 +316,7 @@ def audio_play(
314316
)
315317
self._mode(_AUDIOPLAY_MODE)
316318

317-
def blink(self, rate: Optional[int]) -> Optional[int]:
319+
def blink(self, rate: Optional[int] = None) -> Optional[int]:
318320
"""Updates the blink register"""
319321
# pylint: disable=no-else-return
320322
# This needs to be refactored when it can be tested
@@ -435,7 +437,9 @@ def pixel(
435437

436438
# pylint: enable-msg=too-many-arguments
437439

438-
def image(self, img: Optional[str], frame: Optional[int], blink: bool = False):
440+
def image(
441+
self, img: Image, frame: Optional[int] = None, blink: bool = False
442+
) -> None:
439443
"""Set buffer to value of Python Imaging Library image. The image should
440444
be in 8-bit mode (L) and a size equal to the display size.
441445

adafruit_is31fl3731/matrix.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
try:
3333
from typing import Optional
3434

35-
# Define a placeholder for Image if it's not available
36-
IMAGE = None
35+
try:
36+
from PIL import Image
37+
except ImportError:
38+
# placeholder if PIL unavailable
39+
Image = None
3740
except ImportError as e:
3841
pass
3942

@@ -56,7 +59,7 @@ def pixel_addr(x: int, y: int) -> int:
5659
# for animation. Buffering the full matrix for a quick write is not a
5760
# memory concern here, as by definition this method is used with PIL
5861
# images; we're not running on a RAM-constrained microcontroller.
59-
def image(self, img: Optional[IMAGE], frame: Optional[int], blink: bool = False):
62+
def image(self, img: Image, frame: Optional[int] = None, blink: bool = False):
6063
"""Set buffer to value of Python Imaging Library image.
6164
The image should be in 8-bit mode (L) and a size equal to the
6265
display size.

0 commit comments

Comments
 (0)