From 96ae78b9051e6253f0d6d526fa857257ba0baaf8 Mon Sep 17 00:00:00 2001 From: kibablu Date: Mon, 24 May 2021 10:32:37 +0300 Subject: [PATCH 1/4] Improve static type checking Add type annotation to is_too_long Function on apnstruncate.py file as part of #201 issue Signed-off-by: Omar Mohamed --- sygnal/apnstruncate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sygnal/apnstruncate.py b/sygnal/apnstruncate.py index 03f2362e..91e9cd4e 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, max_length=2048): +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 From ccf60f04ffd87e1151eddc1d8ba51b44f0abf423 Mon Sep 17 00:00:00 2001 From: kibablu Date: Mon, 24 May 2021 10:41:10 +0300 Subject: [PATCH 2/4] Add a changelog on #225 as part of #201 issue Signed-off-by: Omar Mohamed --- changelog.d/225.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/225.misc diff --git a/changelog.d/225.misc b/changelog.d/225.misc new file mode 100644 index 00000000..e62c523c --- /dev/null +++ b/changelog.d/225.misc @@ -0,0 +1 @@ +Improve static type checking. Contributed by Omar Mohamed. \ No newline at end of file From 8ae8f5212c77ab3899cf5577e8ebfb5f45b8493c Mon Sep 17 00:00:00 2001 From: kibablu Date: Tue, 25 May 2021 19:09:08 +0300 Subject: [PATCH 3/4] update on is_too_long as part of #201 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 91e9cd4e..7916e444 100644 --- a/sygnal/apnstruncate.py +++ b/sygnal/apnstruncate.py @@ -26,7 +26,7 @@ class BodyTooLongException(Exception): pass -def is_too_long(payload: Dict[Any, Any], max_length: int = 2048) -> bool: +def is_too_long(payload: dict, 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 From 36fe1e1872eed1ec86487f23b8e4053dacc664a6 Mon Sep 17 00:00:00 2001 From: kibablu Date: Tue, 25 May 2021 19:14:01 +0300 Subject: [PATCH 4/4] update on is_too_long(remove unused Dict) as part of #201 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 7916e444..5448f6f0 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, Dict, List, Tuple, Union +from typing import Any, List, Tuple, Union def json_encode(payload: Any) -> bytes: