11import asyncio
22from enum import Enum
3+ from typing import Any , Dict , Optional
34from uuid import uuid4
45
56PRIORITY_NORMAL = "5"
@@ -29,14 +30,14 @@ class NotificationRequest:
2930
3031 def __init__ (
3132 self ,
32- device_token ,
33- message ,
34- notification_id = None ,
35- time_to_live = None ,
36- priority = None ,
37- collapse_key = None ,
38- push_type = None ,
39- ):
33+ device_token : str ,
34+ message : Dict [ str , Any ] ,
35+ notification_id : Optional [ str ] = None ,
36+ time_to_live : Optional [ int ] = None ,
37+ priority : Optional [ int ] = None ,
38+ collapse_key : Optional [ str ] = None ,
39+ push_type : Optional [ PushType ] = None ,
40+ ) -> None :
4041 self .device_token = device_token
4142 self .message = message
4243 self .notification_id = notification_id or str (uuid4 ())
@@ -49,23 +50,30 @@ def __init__(
4950class NotificationResult :
5051 __slots__ = ("notification_id" , "status" , "description" )
5152
52- def __init__ (self , notification_id , status , description = None ):
53+ def __init__ (
54+ self ,
55+ notification_id : str ,
56+ status : str ,
57+ description : Optional [str ] = None ,
58+ ):
5359 self .notification_id = notification_id
5460 self .status = status
5561 self .description = description
5662
5763 @property
58- def is_successful (self ):
64+ def is_successful (self ) -> bool :
5965 return self .status == APNS_RESPONSE_CODE .SUCCESS
6066
6167
6268class DynamicBoundedSemaphore (asyncio .BoundedSemaphore ):
69+ _bound_value : int
70+
6371 @property
64- def bound (self ):
72+ def bound (self ) -> int :
6573 return self ._bound_value
6674
6775 @bound .setter
68- def bound (self , new_bound ) :
76+ def bound (self , new_bound : int ) -> None :
6977 if new_bound > self ._bound_value :
7078 if self ._value > 0 :
7179 self ._value += new_bound - self ._bound_value
@@ -76,13 +84,13 @@ def bound(self, new_bound):
7684 self ._value -= self ._bound_value - new_bound
7785 self ._bound_value = new_bound
7886
79- def release (self ):
87+ def release (self ) -> None :
8088 self ._value += 1
8189 if self ._value > self ._bound_value :
8290 self ._value = self ._bound_value
8391 self ._wake_up_next ()
8492
85- def destroy (self , exc ) :
93+ def destroy (self , exc : Exception ) -> None :
8694 while self ._waiters :
8795 waiter = self ._waiters .popleft ()
8896 if not waiter .done ():
0 commit comments