From 61563cbd065f6c5852623dc30f82a91b98e39f42 Mon Sep 17 00:00:00 2001 From: kibablu Date: Tue, 1 Jun 2021 19:25:17 +0300 Subject: [PATCH 1/3] Improve static type checking Add type annotation to truncate Function on apnstruncate.py file as part of #201 issue Signed-off-by: Omar Mohamed --- sygnal/apnstruncate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sygnal/apnstruncate.py b/sygnal/apnstruncate.py index 5448f6f0..ba6ea5c7 100644 --- a/sygnal/apnstruncate.py +++ b/sygnal/apnstruncate.py @@ -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: @@ -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 @@ -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]: """ Truncate APNs fields to make the payload fit within the max length specified. From 9d4c39ac9111bf25de10f5ed592c488090b0448a Mon Sep 17 00:00:00 2001 From: kibablu Date: Tue, 1 Jun 2021 19:30:57 +0300 Subject: [PATCH 2/3] Add a changelog on 227 PR Signed-off-by: Omar Mohamed --- changelog.d/227.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/227.misc diff --git a/changelog.d/227.misc b/changelog.d/227.misc new file mode 100644 index 00000000..e62c523c --- /dev/null +++ b/changelog.d/227.misc @@ -0,0 +1 @@ +Improve static type checking. Contributed by Omar Mohamed. \ No newline at end of file From 31487afcecc4c0b8942dfb3da7baa0f7ede1a26f Mon Sep 17 00:00:00 2001 From: kibablu Date: Sat, 5 Jun 2021 14:38:04 +0300 Subject: [PATCH 3/3] Modified truncate Function on #227 Part of #201 issue Signed-off-by: Omar Mohamed --- sygnal/apnstruncate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sygnal/apnstruncate.py b/sygnal/apnstruncate.py index ba6ea5c7..b81ed698 100644 --- a/sygnal/apnstruncate.py +++ b/sygnal/apnstruncate.py @@ -38,7 +38,7 @@ def is_too_long(payload: Dict[Any, Any], max_length: int = 2048) -> bool: return len(json_encode(payload)) > max_length -def truncate(payload: Dict[Any, Any], max_length: int = 2048) -> Dict[str, Any]: +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.