From f5ca07e3fed9a884735f1aa4ceb92dbca02b418e Mon Sep 17 00:00:00 2001 From: Jreanah Date: Mon, 24 Apr 2023 10:46:14 -0600 Subject: [PATCH 1/4] Added type hints to __init__.py and apple.py --- adafruit_display_notification/__init__.py | 12 ++++++++---- adafruit_display_notification/apple.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/adafruit_display_notification/__init__.py b/adafruit_display_notification/__init__.py index fbeb361..016bd12 100755 --- a/adafruit_display_notification/__init__.py +++ b/adafruit_display_notification/__init__.py @@ -11,11 +11,15 @@ """ import displayio - from adafruit_display_text import label - import terminalio +# For older versions, typing may need to be imported +try: + from typing import List, Tuple +except ImportError + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git" @@ -46,7 +50,7 @@ def __init__(self, width, height, *, dark_mode=True): class PlainNotification(displayio.Group): """Plain text widget with a title and message.""" - def __init__(self, title, message, width, height, *, dark_mode=True): + def __init__(self, title: str, message: str, width: int, height: int, *, dark_mode=True): super().__init__() # Set text, font, and color @@ -71,7 +75,7 @@ def __init__(self, title, message, width, height, *, dark_mode=True): # cribbed from pyportal @staticmethod - def _wrap_nicely(string, max_chars): + def _wrap_nicely(string: str, max_chars: int) -> List[str]: """A helper that will return a list of lines with word-break wrapping. :param str string: The text to be wrapped. :param int max_chars: The maximum number of characters on a line before wrapping. diff --git a/adafruit_display_notification/apple.py b/adafruit_display_notification/apple.py index 97a7ec9..524c5e9 100755 --- a/adafruit_display_notification/apple.py +++ b/adafruit_display_notification/apple.py @@ -18,9 +18,16 @@ def create_notification_widget( - notification, max_width, max_height, *, color_count=2**16 -): - """Creates a notification widget for the given Apple notification.""" + notification: object, max_width: int, max_height: int, + *, color_count: int=2**16): + """ + Creates a notification widget for the given Apple notification. + :param notification object: Object with attributes title and message + :param max_width int: Max Width of the notification + :param max_height int: Max Height of the Notication + :param color_count int: Number of colors, default is 2**16 + + """ # pylint: disable=unused-argument return PlainNotification( notification.title, notification.message, max_width, max_height From d0fabeafeb7c5433c7890faa4d138a3c62fe0714 Mon Sep 17 00:00:00 2001 From: Jreanah Date: Mon, 24 Apr 2023 10:55:49 -0600 Subject: [PATCH 2/4] Added type hints to NotificationFree --- adafruit_display_notification/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_display_notification/__init__.py b/adafruit_display_notification/__init__.py index 016bd12..660b1ad 100755 --- a/adafruit_display_notification/__init__.py +++ b/adafruit_display_notification/__init__.py @@ -1,5 +1,5 @@ # SPDX-FileCopyrightText: 2019 Scott Shawcroft for Adafruit Industries -# + # SPDX-License-Identifier: MIT """ @@ -31,7 +31,7 @@ class NotificationFree(displayio.Group): """Widget to show when no notifications are active.""" - def __init__(self, width, height, *, dark_mode=True): + def __init__(self, width: int, height: int, *, dark_mode=True): # pylint: disable=unused-argument super().__init__() @@ -50,7 +50,7 @@ def __init__(self, width, height, *, dark_mode=True): class PlainNotification(displayio.Group): """Plain text widget with a title and message.""" - def __init__(self, title: str, message: str, width: int, height: int, *, dark_mode=True): + def __init__(self, title: str, message: str, width: int, height: int, *, dark_mode: bool=True): super().__init__() # Set text, font, and color From c1d0d7110a6ae51d586a18074d36779ee7e07b8d Mon Sep 17 00:00:00 2001 From: Jreanah Date: Mon, 24 Apr 2023 11:07:41 -0600 Subject: [PATCH 3/4] Fixed missing colon --- adafruit_display_notification/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_display_notification/__init__.py b/adafruit_display_notification/__init__.py index 660b1ad..29cdaba 100755 --- a/adafruit_display_notification/__init__.py +++ b/adafruit_display_notification/__init__.py @@ -17,7 +17,7 @@ # For older versions, typing may need to be imported try: from typing import List, Tuple -except ImportError +except ImportError: pass __version__ = "0.0.0+auto.0" From 99b7d02ac62ecf801de73e81bd0e165ed9ad2905 Mon Sep 17 00:00:00 2001 From: Jreanah Date: Mon, 24 Apr 2023 11:40:28 -0600 Subject: [PATCH 4/4] Added Union for optional types --- adafruit_display_notification/__init__.py | 8 +++++--- adafruit_display_notification/apple.py | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/adafruit_display_notification/__init__.py b/adafruit_display_notification/__init__.py index 29cdaba..c2182b2 100755 --- a/adafruit_display_notification/__init__.py +++ b/adafruit_display_notification/__init__.py @@ -16,7 +16,7 @@ # For older versions, typing may need to be imported try: - from typing import List, Tuple + from typing import List, Tuple, Optional, Union except ImportError: pass @@ -31,7 +31,8 @@ class NotificationFree(displayio.Group): """Widget to show when no notifications are active.""" - def __init__(self, width: int, height: int, *, dark_mode=True): + def __init__(self, width: Union[int, float], height: Union[int, float], *, + dark_mode: Union[bool, int]=True): # pylint: disable=unused-argument super().__init__() @@ -50,7 +51,8 @@ def __init__(self, width: int, height: int, *, dark_mode=True): class PlainNotification(displayio.Group): """Plain text widget with a title and message.""" - def __init__(self, title: str, message: str, width: int, height: int, *, dark_mode: bool=True): + def __init__(self, title: str, message: str, width: Union[int, float], height: Union[int, float], + *, dark_mode: Union[bool, int]=True): super().__init__() # Set text, font, and color diff --git a/adafruit_display_notification/apple.py b/adafruit_display_notification/apple.py index 524c5e9..6153778 100755 --- a/adafruit_display_notification/apple.py +++ b/adafruit_display_notification/apple.py @@ -13,12 +13,17 @@ from . import PlainNotification +try: + from typing import Union +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git" def create_notification_widget( - notification: object, max_width: int, max_height: int, + notification: object, max_width: Union[int, float], max_height: Union[int, float], *, color_count: int=2**16): """ Creates a notification widget for the given Apple notification.