From a85229e4d44541f5e46b2f385de3c82ad86cc944 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 27 Nov 2023 10:12:14 -0800 Subject: [PATCH 1/2] Fix typing for color565 function --- adafruit_rgb_display/rgb.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_rgb_display/rgb.py b/adafruit_rgb_display/rgb.py index 5c906f7..26b6fe0 100644 --- a/adafruit_rgb_display/rgb.py +++ b/adafruit_rgb_display/rgb.py @@ -47,14 +47,14 @@ def color565( - r: Union[int, Tuple[int, int, int], List[int]], - g: int = 0, - b: int = 0, + r: Union[int, Tuple[int, int, int], List[int, int, int]], + g: Optional[int] = 0, + b: Optional[int] = 0, ) -> int: """Convert red, green and blue values (0-255) into a 16-bit 565 encoding. As a convenience this is also available in the parent adafruit_rgb_display package namespace.""" - if not isinstance(r, int): # see if the first var is a tuple/list + if isinstance(r, (tuple, list)): # see if the first var is a tuple/list red, g, b = r else: red = r From c89be83fbec7fb9ab852ea45e84f6dd12eca8065 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 27 Nov 2023 10:20:15 -0800 Subject: [PATCH 2/2] Update color565 to just make sure we get what we expect --- adafruit_rgb_display/rgb.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_rgb_display/rgb.py b/adafruit_rgb_display/rgb.py index 26b6fe0..a874201 100644 --- a/adafruit_rgb_display/rgb.py +++ b/adafruit_rgb_display/rgb.py @@ -47,7 +47,7 @@ def color565( - r: Union[int, Tuple[int, int, int], List[int, int, int]], + r: Union[int, Tuple[int, int, int], List[int]], g: Optional[int] = 0, b: Optional[int] = 0, ) -> int: @@ -55,7 +55,12 @@ def color565( a convenience this is also available in the parent adafruit_rgb_display package namespace.""" if isinstance(r, (tuple, list)): # see if the first var is a tuple/list - red, g, b = r + if len(r) >= 3: + red, g, b = r + else: + raise ValueError( + "Not enough values to unpack (expected 3, got %d)" % len(r) + ) else: red = r return (red & 0xF8) << 8 | (g & 0xFC) << 3 | b >> 3