From 1ef3d98925fcfa3333c586850fef04be3b93fa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milosch=20F=C3=BCllgraf?= Date: Sun, 4 Jun 2023 09:33:09 +0200 Subject: [PATCH 1/3] Add type hints --- adafruit_display_notification/__init__.py | 19 ++++++++++++++++--- adafruit_display_notification/apple.py | 8 ++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/adafruit_display_notification/__init__.py b/adafruit_display_notification/__init__.py index fbeb361..11feeb6 100755 --- a/adafruit_display_notification/__init__.py +++ b/adafruit_display_notification/__init__.py @@ -16,6 +16,11 @@ import terminalio +try: + from typing import List +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git" @@ -27,7 +32,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: bool = True): # pylint: disable=unused-argument super().__init__() @@ -46,7 +51,15 @@ 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: bool = True + ): super().__init__() # Set text, font, and color @@ -71,7 +84,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..e036c2e 100755 --- a/adafruit_display_notification/apple.py +++ b/adafruit_display_notification/apple.py @@ -18,8 +18,12 @@ def create_notification_widget( - notification, max_width, max_height, *, color_count=2**16 -): + notification: PlainNotification, + max_width: int, + max_height: int, + *, + color_count: int = 2**16 +) -> PlainNotification: """Creates a notification widget for the given Apple notification.""" # pylint: disable=unused-argument return PlainNotification( From faa73bc62b9921ed9be7a81e46ae5427347dfbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milosch=20F=C3=BCllgraf?= Date: Sun, 4 Jun 2023 09:51:37 +0200 Subject: [PATCH 2/3] Add correct type of apple `create_notification_widget()` --- adafruit_display_notification/apple.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_display_notification/apple.py b/adafruit_display_notification/apple.py index e036c2e..ce2f50d 100755 --- a/adafruit_display_notification/apple.py +++ b/adafruit_display_notification/apple.py @@ -13,12 +13,17 @@ from . import PlainNotification +try: + from adafruit_ble_apple_notification_center import Notification +except ImportError: + pass + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git" def create_notification_widget( - notification: PlainNotification, + notification: Notification, max_width: int, max_height: int, *, From d19ab0e0f66f96d9bc31bb87e4584d71c4c33867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milosch=20F=C3=BCllgraf?= Date: Tue, 6 Jun 2023 15:58:02 +0200 Subject: [PATCH 3/3] Add typing import to prevent other typing-only imports from being loaded at runtime --- adafruit_display_notification/apple.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_display_notification/apple.py b/adafruit_display_notification/apple.py index ce2f50d..a50a899 100755 --- a/adafruit_display_notification/apple.py +++ b/adafruit_display_notification/apple.py @@ -14,6 +14,9 @@ from . import PlainNotification try: + # unused typing-import to prevent the other typing-only imports from being loaded at runtime + from typing import Any # pylint: disable=unused-import + from adafruit_ble_apple_notification_center import Notification except ImportError: pass