Skip to content
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

Improve static type checking #227

Merged
merged 3 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changelog.d/227.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve static type checking. Contributed by Omar Mohamed.
6 changes: 3 additions & 3 deletions sygnal/apnstruncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Copied and adapted from
# https://raw.githubusercontent.com/matrix-org/pushbaby/master/pushbaby/truncate.py
import json
from typing import Any, List, Tuple, Union
from typing import Any, Dict, List, Tuple, Union


def json_encode(payload: Any) -> bytes:
Expand All @@ -26,7 +26,7 @@ class BodyTooLongException(Exception):
pass


def is_too_long(payload: dict, max_length: int = 2048) -> bool:
def is_too_long(payload: Dict[Any, Any], max_length: int = 2048) -> bool:
"""
Returns True if the given payload dictionary is too long for a push.
Note that the maximum is now 2kB "In iOS 8 and later" although in
Expand All @@ -38,7 +38,7 @@ def is_too_long(payload: dict, max_length: int = 2048) -> bool:
return len(json_encode(payload)) > max_length


def truncate(payload, max_length=2048):
def truncate(payload: Dict[Any, Any], max_length: int = 2048) -> Dict[str, Any]:
callahad marked this conversation as resolved.
Show resolved Hide resolved
"""
Truncate APNs fields to make the payload fit within the max length
specified.
Expand Down