From 993b21baad9e265717e55f73c9b96be732d8d5c1 Mon Sep 17 00:00:00 2001 From: GTB Date: Wed, 26 Apr 2023 11:41:35 -0600 Subject: [PATCH 1/2] style: add type annotation and try/catch import error for typing issue #13 --- adafruit_matrixkeypad.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/adafruit_matrixkeypad.py b/adafruit_matrixkeypad.py index e951b4e..29647d1 100644 --- a/adafruit_matrixkeypad.py +++ b/adafruit_matrixkeypad.py @@ -27,6 +27,13 @@ # imports from digitalio import Direction, Pull +# Since the board may or may not have access to the typing library we need +# to have this in a try/except to enable type +try: + from typing import List +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixKeypad.git" @@ -34,8 +41,9 @@ class Matrix_Keypad: """Driver for passive matrix keypads - any size""" - def __init__(self, row_pins, col_pins, keys): - """Initialise the driver with the correct size and key list. + def __init__(self, row_pins: List = [], col_pins: List = [], keys:List = []): + """ + Initialise the driver with the correct size and key list. :param list row_pins: a list of DigitalInOut objects corresponding to the rows :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): self.keys = keys @property - def pressed_keys(self): - """An array containing all detected keys that are pressed from the initalized - list-of-lists passed in during creation""" + def pressed_keys(self) -> List: + """ + An array containing all detected keys that are pressed from the initalized + list-of-lists passed in during creation + + :return: a list of keys that are pressed + """ # make a list of all the keys that are detected pressed = [] From 90f5d75c5c86397a34b8190f79d87b50145ebe24 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 5 Jun 2023 16:35:10 -0500 Subject: [PATCH 2/2] remove empty default values. add types of items in lists of args --- adafruit_matrixkeypad.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adafruit_matrixkeypad.py b/adafruit_matrixkeypad.py index 29647d1..5f0857b 100644 --- a/adafruit_matrixkeypad.py +++ b/adafruit_matrixkeypad.py @@ -31,6 +31,7 @@ # to have this in a try/except to enable type try: from typing import List + from digitalio import DigitalInOut except ImportError: pass @@ -41,7 +42,12 @@ class Matrix_Keypad: """Driver for passive matrix keypads - any size""" - def __init__(self, row_pins: List = [], col_pins: List = [], keys:List = []): + def __init__( + self, + row_pins: List[DigitalInOut], + col_pins: List[DigitalInOut], + keys: List[List], + ) -> None: """ Initialise the driver with the correct size and key list.