From cb08d4fbad1113c88254c2195795b0874f3064d3 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 15:03:48 -0400 Subject: [PATCH 1/3] Add Missing Type Annotations --- adafruit_touchscreen.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/adafruit_touchscreen.py b/adafruit_touchscreen.py index b1aa0fd..fb79799 100644 --- a/adafruit_touchscreen.py +++ b/adafruit_touchscreen.py @@ -27,8 +27,13 @@ from digitalio import DigitalInOut from analogio import AnalogIn +try: + from typing import Optional, Tuple, Union +except ImportError: + pass -def map_range(x, in_min, in_max, out_min, out_max): + +def map_range(x, in_min, in_max, out_min, out_max) -> float: """ Maps a number from one range to another. @@ -89,17 +94,17 @@ class Touchscreen: def __init__( self, - x1_pin, - x2_pin, - y1_pin, - y2_pin, + x1_pin: DigitalInOut, + x2_pin: DigitalInOut, + y1_pin: DigitalInOut, + y2_pin: DigitalInOut, *, - x_resistance=None, - samples=4, - z_threshold=10000, - calibration=None, - size=None - ): + x_resistance: Optional[int] = None, + samples: int = 4, + z_threshold: int = 10000, + calibration: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None, + size: Optional[Tuple[int, int]] = None + ) -> None: self._xm_pin = x1_pin self._xp_pin = x2_pin @@ -115,7 +120,9 @@ def __init__( self._zthresh = z_threshold @property - def touch_point(self): # pylint: disable=too-many-locals + def touch_point( + self, + ) -> Union[None, Tuple[float, float, int]]: # pylint: disable=too-many-locals """A tuple that represents the x, y and z (touch pressure) coordinates of a touch. Or, None if no touch is detected""" z_1 = z_2 = z = None From 35a9e1b83fd08aeac847636d92ca42de5bb2cecb Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 15:09:46 -0400 Subject: [PATCH 2/3] Add Missing Type Annotations --- adafruit_touchscreen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_touchscreen.py b/adafruit_touchscreen.py index fb79799..8b61132 100644 --- a/adafruit_touchscreen.py +++ b/adafruit_touchscreen.py @@ -122,7 +122,7 @@ def __init__( @property def touch_point( self, - ) -> Union[None, Tuple[float, float, int]]: # pylint: disable=too-many-locals + ) -> Union[None, Tuple[int, int, int]]: # pylint: disable=too-many-locals """A tuple that represents the x, y and z (touch pressure) coordinates of a touch. Or, None if no touch is detected""" z_1 = z_2 = z = None From a511cec806411c80b5a3280b512a09a5d74eac0e Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 2 Sep 2022 16:07:12 -0400 Subject: [PATCH 3/3] Add Missing Type Annotations --- adafruit_touchscreen.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/adafruit_touchscreen.py b/adafruit_touchscreen.py index 8b61132..5bf0fe0 100644 --- a/adafruit_touchscreen.py +++ b/adafruit_touchscreen.py @@ -28,12 +28,13 @@ from analogio import AnalogIn try: - from typing import Optional, Tuple, Union + from typing import Optional, Tuple + from microcontroller import Pin except ImportError: pass -def map_range(x, in_min, in_max, out_min, out_max) -> float: +def map_range(x: float, in_min: int, in_max: int, out_min: int, out_max: int) -> float: """ Maps a number from one range to another. @@ -94,10 +95,10 @@ class Touchscreen: def __init__( self, - x1_pin: DigitalInOut, - x2_pin: DigitalInOut, - y1_pin: DigitalInOut, - y2_pin: DigitalInOut, + x1_pin: Pin, + x2_pin: Pin, + y1_pin: Pin, + y2_pin: Pin, *, x_resistance: Optional[int] = None, samples: int = 4, @@ -122,7 +123,7 @@ def __init__( @property def touch_point( self, - ) -> Union[None, Tuple[int, int, int]]: # pylint: disable=too-many-locals + ) -> Optional[Tuple[int, int, int]]: # pylint: disable=too-many-locals """A tuple that represents the x, y and z (touch pressure) coordinates of a touch. Or, None if no touch is detected""" z_1 = z_2 = z = None