Add type annotations (PEP 484) (#25)

This commit is contained in:
Sergey Petrov
2019-07-29 01:26:15 +03:00
committed by GitHub
parent be7438a653
commit fde28abb04
9 changed files with 151 additions and 76 deletions
+31 -11
View File
@@ -1,11 +1,21 @@
from typing import Any, Dict, List, Optional, Union, Iterable
MAX_PAYLOAD_SIZE = 4096
class PayloadAlert(object):
def __init__(self, title=None, title_localized_key=None, title_localized_args=None,
body=None, body_localized_key=None, body_localized_args=None,
action_localized_key=None, action=None,
launch_image=None):
def __init__(
self,
title: Optional[str] = None,
title_localized_key: Optional[str] = None,
title_localized_args: Optional[List[str]] = None,
body: Optional[str] = None,
body_localized_key: Optional[str] = None,
body_localized_args: Optional[List[str]] = None,
action_localized_key: Optional[str] = None,
action: Optional[str] = None,
launch_image: Optional[str] = None
) -> None:
self.title = title
self.title_localized_key = title_localized_key
self.title_localized_args = title_localized_args
@@ -16,8 +26,8 @@ class PayloadAlert(object):
self.action = action
self.launch_image = launch_image
def dict(self):
result = {}
def dict(self) -> Dict[str, Any]:
result = {} # type: Dict[str, Any]
if self.title:
result['title'] = self.title
@@ -45,9 +55,18 @@ class PayloadAlert(object):
class Payload(object):
def __init__(self, alert=None, badge=None, sound=None,
content_available=False, mutable_content=False,
category=None, url_args=None, custom=None, thread_id=None):
def __init__(
self,
alert: Union[PayloadAlert, str, None] = None,
badge: Optional[int] = None,
sound: Optional[str] = None,
category: Optional[str] = None,
url_args: Optional[Iterable[str]] = None,
custom: Optional[Dict[str, Any]] = None,
thread_id: Optional[str] = None,
content_available: bool = False,
mutable_content: bool = False,
) -> None:
self.alert = alert
self.badge = badge
self.sound = sound
@@ -58,10 +77,11 @@ class Payload(object):
self.mutable_content = mutable_content
self.thread_id = thread_id
def dict(self):
def dict(self) -> Dict[str, Any]:
result = {
'aps': {}
}
} # type: Dict[str, Any]
if self.alert is not None:
if isinstance(self.alert, PayloadAlert):
result['aps']['alert'] = self.alert.dict()