Skip to content

Commit c624456

Browse files
authored
Merge pull request #1 from jreanah/add_type_hints
Add type hints
2 parents 83dbf5b + c1d0d71 commit c624456

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

adafruit_display_notification/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-FileCopyrightText: 2019 Scott Shawcroft for Adafruit Industries
2-
#
2+
33
# SPDX-License-Identifier: MIT
44

55
"""
@@ -11,11 +11,15 @@
1111
"""
1212

1313
import displayio
14-
1514
from adafruit_display_text import label
16-
1715
import terminalio
1816

17+
# For older versions, typing may need to be imported
18+
try:
19+
from typing import List, Tuple
20+
except ImportError:
21+
pass
22+
1923
__version__ = "0.0.0+auto.0"
2024
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git"
2125

@@ -27,7 +31,7 @@
2731
class NotificationFree(displayio.Group):
2832
"""Widget to show when no notifications are active."""
2933

30-
def __init__(self, width, height, *, dark_mode=True):
34+
def __init__(self, width: int, height: int, *, dark_mode=True):
3135
# pylint: disable=unused-argument
3236
super().__init__()
3337

@@ -46,7 +50,7 @@ def __init__(self, width, height, *, dark_mode=True):
4650
class PlainNotification(displayio.Group):
4751
"""Plain text widget with a title and message."""
4852

49-
def __init__(self, title, message, width, height, *, dark_mode=True):
53+
def __init__(self, title: str, message: str, width: int, height: int, *, dark_mode: bool=True):
5054
super().__init__()
5155

5256
# Set text, font, and color
@@ -71,7 +75,7 @@ def __init__(self, title, message, width, height, *, dark_mode=True):
7175

7276
# cribbed from pyportal
7377
@staticmethod
74-
def _wrap_nicely(string, max_chars):
78+
def _wrap_nicely(string: str, max_chars: int) -> List[str]:
7579
"""A helper that will return a list of lines with word-break wrapping.
7680
:param str string: The text to be wrapped.
7781
:param int max_chars: The maximum number of characters on a line before wrapping.

adafruit_display_notification/apple.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818

1919

2020
def create_notification_widget(
21-
notification, max_width, max_height, *, color_count=2**16
22-
):
23-
"""Creates a notification widget for the given Apple notification."""
21+
notification: object, max_width: int, max_height: int,
22+
*, color_count: int=2**16):
23+
"""
24+
Creates a notification widget for the given Apple notification.
25+
:param notification object: Object with attributes title and message
26+
:param max_width int: Max Width of the notification
27+
:param max_height int: Max Height of the Notication
28+
:param color_count int: Number of colors, default is 2**16
29+
30+
"""
2431
# pylint: disable=unused-argument
2532
return PlainNotification(
2633
notification.title, notification.message, max_width, max_height

0 commit comments

Comments
 (0)