Skip to content

Add type hints #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions adafruit_display_notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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__()

Expand All @@ -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
Expand All @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions adafruit_display_notification/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@

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

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git"


def create_notification_widget(
notification, max_width, max_height, *, color_count=2**16
):
notification: Notification,
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(
Expand Down