Skip to content

Commit

Permalink
Improve static type checking (#227)
Browse files Browse the repository at this point in the history
Add type annotation to truncate Function on apnstruncate.py file
as part of #201 issue

Signed-off-by: Omar Mohamed <[email protected]>
  • Loading branch information
kibablu authored Jun 7, 2021
1 parent 656c0ea commit 4f4d7ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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[str, Any], max_length: int = 2048) -> Dict[str, Any]:
"""
Truncate APNs fields to make the payload fit within the max length
specified.
Expand Down

0 comments on commit 4f4d7ce

Please sign in to comment.