Skip to content

Commit 7b5a196

Browse files
authored
Merge pull request #16 from gtbcoding/isssue/13-type-annotation
type annotation
2 parents 36141a6 + 90f5d75 commit 7b5a196

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

adafruit_matrixkeypad.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,29 @@
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+
from digitalio import DigitalInOut
35+
except ImportError:
36+
pass
37+
3038
__version__ = "0.0.0+auto.0"
3139
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixKeypad.git"
3240

3341

3442
class Matrix_Keypad:
3543
"""Driver for passive matrix keypads - any size"""
3644

37-
def __init__(self, row_pins, col_pins, keys):
38-
"""Initialise the driver with the correct size and key list.
45+
def __init__(
46+
self,
47+
row_pins: List[DigitalInOut],
48+
col_pins: List[DigitalInOut],
49+
keys: List[List],
50+
) -> None:
51+
"""
52+
Initialise the driver with the correct size and key list.
3953
4054
:param list row_pins: a list of DigitalInOut objects corresponding to the rows
4155
:param list col_pins: a list of DigitalInOut objects corresponding to the colums
@@ -51,9 +65,13 @@ def __init__(self, row_pins, col_pins, keys):
5165
self.keys = keys
5266

5367
@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"""
68+
def pressed_keys(self) -> List:
69+
"""
70+
An array containing all detected keys that are pressed from the initalized
71+
list-of-lists passed in during creation
72+
73+
:return: a list of keys that are pressed
74+
"""
5775
# make a list of all the keys that are detected
5876
pressed = []
5977

0 commit comments

Comments
 (0)