Skip to content

Commit 993b21b

Browse files
committed
style: add type annotation and try/catch import error for typing
issue #13
1 parent 7d48dba commit 993b21b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

adafruit_matrixkeypad.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@
2727
# imports
2828
from digitalio import Direction, Pull
2929

30+
# Since the board may or may not have access to the typing library we need
31+
# to have this in a try/except to enable type
32+
try:
33+
from typing import List
34+
except ImportError:
35+
pass
36+
3037
__version__ = "0.0.0+auto.0"
3138
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixKeypad.git"
3239

3340

3441
class Matrix_Keypad:
3542
"""Driver for passive matrix keypads - any size"""
3643

37-
def __init__(self, row_pins, col_pins, keys):
38-
"""Initialise the driver with the correct size and key list.
44+
def __init__(self, row_pins: List = [], col_pins: List = [], keys:List = []):
45+
"""
46+
Initialise the driver with the correct size and key list.
3947
4048
:param list row_pins: a list of DigitalInOut objects corresponding to the rows
4149
:param list col_pins: a list of DigitalInOut objects corresponding to the colums
@@ -51,9 +59,13 @@ def __init__(self, row_pins, col_pins, keys):
5159
self.keys = keys
5260

5361
@property
54-
def pressed_keys(self):
55-
"""An array containing all detected keys that are pressed from the initalized
56-
list-of-lists passed in during creation"""
62+
def pressed_keys(self) -> List:
63+
"""
64+
An array containing all detected keys that are pressed from the initalized
65+
list-of-lists passed in during creation
66+
67+
:return: a list of keys that are pressed
68+
"""
5769
# make a list of all the keys that are detected
5870
pressed = []
5971

0 commit comments

Comments
 (0)