2525# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2626# POSSIBILITY OF SUCH DAMAGE.
2727
28+ from __future__ import annotations
29+
2830import asyncio
31+ from collections .abc import Iterator
2932import concurrent .futures as cf
3033from itertools import chain
3134import os
35+ from typing import Any , Optional , Union
3236
3337from . import __version__ , common , plugins
3438from .apprise_attachment import AppriseAttachment
3539from .apprise_config import AppriseConfig
3640from .asset import AppriseAsset
41+ from .common import ContentLocation
3742from .config .base import ConfigBase
3843from .conversion import convert_between
3944from .emojis import apply_emojis
5257class Apprise :
5358 """Our Notification Manager."""
5459
55- def __init__ (self , servers = None , asset = None , location = None , debug = False ):
60+ def __init__ (
61+ self ,
62+ servers : Optional [
63+ Union [
64+ str ,
65+ dict ,
66+ NotifyBase ,
67+ AppriseConfig ,
68+ ConfigBase ,
69+ list [Union [str , dict , NotifyBase , AppriseConfig , ConfigBase ]],
70+ ]
71+ ] = None ,
72+ asset : Optional [AppriseAsset ] = None ,
73+ location : Optional [ContentLocation ] = None ,
74+ debug : bool = False ,
75+ ) -> None :
5676 """Loads a set of server urls while applying the Asset() module to each
5777 if specified.
5878
@@ -89,7 +109,12 @@ def __init__(self, servers=None, asset=None, location=None, debug=False):
89109 self .location = location
90110
91111 @staticmethod
92- def instantiate (url , asset = None , tag = None , suppress_exceptions = True ):
112+ def instantiate (
113+ url : Union [str , dict ],
114+ asset : Optional [AppriseAsset ] = None ,
115+ tag : Optional [Union [str , list [str ]]] = None ,
116+ suppress_exceptions : bool = True ,
117+ ) -> Optional [NotifyBase ]:
93118 """Returns the instance of a instantiated plugin based on the provided
94119 Server URL. If the url fails to be parsed, then None is returned.
95120
@@ -236,7 +261,19 @@ def instantiate(url, asset=None, tag=None, suppress_exceptions=True):
236261
237262 return plugin
238263
239- def add (self , servers , asset = None , tag = None ):
264+ def add (
265+ self ,
266+ servers : Union [
267+ str ,
268+ dict ,
269+ NotifyBase ,
270+ AppriseConfig ,
271+ ConfigBase ,
272+ list [Union [str , dict , NotifyBase , AppriseConfig , ConfigBase ]],
273+ ],
274+ asset : Optional [AppriseAsset ] = None ,
275+ tag : Optional [Union [str , list [str ]]] = None ,
276+ ) -> bool :
240277 """Adds one or more server URLs into our list.
241278
242279 You can override the global asset if you wish by including it with the
@@ -306,11 +343,15 @@ def add(self, servers, asset=None, tag=None):
306343 # Return our status
307344 return return_status
308345
309- def clear (self ):
346+ def clear (self ) -> None :
310347 """Empties our server list."""
311348 self .servers [:] = []
312349
313- def find (self , tag = common .MATCH_ALL_TAG , match_always = True ):
350+ def find (
351+ self ,
352+ tag : Any = common .MATCH_ALL_TAG ,
353+ match_always : bool = True ,
354+ ) -> Iterator [NotifyBase ]:
314355 """Returns a list of all servers matching against the tag specified."""
315356
316357 # Build our tag setup
@@ -352,15 +393,15 @@ def find(self, tag=common.MATCH_ALL_TAG, match_always=True):
352393
353394 def notify (
354395 self ,
355- body ,
356- title = "" ,
357- notify_type = common .NotifyType .INFO ,
358- body_format = None ,
359- tag = common .MATCH_ALL_TAG ,
360- match_always = True ,
361- attach = None ,
362- interpret_escapes = None ,
363- ):
396+ body : Union [ str , bytes ] ,
397+ title : Union [ str , bytes ] = "" ,
398+ notify_type : common . NotifyType = common .NotifyType .INFO ,
399+ body_format : Optional [ str ] = None ,
400+ tag : Any = common .MATCH_ALL_TAG ,
401+ match_always : bool = True ,
402+ attach : Any = None ,
403+ interpret_escapes : Optional [ bool ] = None ,
404+ ) -> Optional [ bool ] :
364405 """Send a notification to all the plugins previously loaded.
365406
366407 If the body_format specified is NotifyFormat.MARKDOWN, it will be
@@ -410,7 +451,11 @@ def notify(
410451 parallel_result = Apprise ._notify_parallel_threadpool (* parallel_calls )
411452 return sequential_result and parallel_result
412453
413- async def async_notify (self , * args , ** kwargs ):
454+ async def async_notify (
455+ self ,
456+ * args : Any ,
457+ ** kwargs : Any
458+ ) -> Optional [bool ]:
414459 """Send a notification to all the plugins previously loaded, for
415460 asynchronous callers.
416461
@@ -712,7 +757,12 @@ async def do_call(server, kwargs):
712757
713758 return all (results )
714759
715- def details (self , lang = None , show_requirements = False , show_disabled = False ):
760+ def details (
761+ self ,
762+ lang : Optional [str ] = None ,
763+ show_requirements : bool = False ,
764+ show_disabled : bool = False ,
765+ ) -> dict [str , Any ]:
716766 """Returns the details associated with the Apprise object."""
717767
718768 # general object returned
@@ -789,7 +839,7 @@ def details(self, lang=None, show_requirements=False, show_disabled=False):
789839
790840 return response
791841
792- def urls (self , privacy = False ):
842+ def urls (self , privacy : bool = False ) -> list [ str ] :
793843 """Returns all of the loaded URLs defined in this apprise object."""
794844 urls = []
795845 for s in self .servers :
@@ -800,7 +850,7 @@ def urls(self, privacy=False):
800850 urls .append (s .url (privacy = privacy ))
801851 return urls
802852
803- def pop (self , index ) :
853+ def pop (self , index : int ) -> NotifyBase :
804854 """Removes an indexed Notification Service from the stack and returns
805855 it.
806856
@@ -845,7 +895,7 @@ def pop(self, index):
845895 # If we reach here, then we indexed out of range
846896 raise IndexError ("list index out of range" )
847897
848- def __getitem__ (self , index ) :
898+ def __getitem__ (self , index : int ) -> NotifyBase :
849899 """Returns the indexed server entry of a loaded notification server."""
850900 # Tracking variables
851901 prev_offset = - 1
@@ -877,7 +927,7 @@ def __getitem__(self, index):
877927 # If we reach here, then we indexed out of range
878928 raise IndexError ("list index out of range" )
879929
880- def __getstate__ (self ):
930+ def __getstate__ (self ) -> dict [ str , object ] :
881931 """Pickle Support dumps()"""
882932 attributes = {
883933 "asset" : self .asset ,
@@ -893,28 +943,36 @@ def __getstate__(self):
893943 ],
894944 "locale" : self .locale ,
895945 "debug" : self .debug ,
896- "location" : self .location ,
946+ "location" : self .location . value if self . location else None ,
897947 }
898948
899949 return attributes
900950
901- def __setstate__ (self , state ) :
951+ def __setstate__ (self , state : dict [ str , object ]) -> None :
902952 """Pickle Support loads()"""
903953 self .servers = []
904954 self .asset = state ["asset" ]
905955 self .locale = state ["locale" ]
906- self .location = state ["location" ]
956+
957+ location = state .get ("location" )
958+ self .location = (
959+ location if isinstance (location , ContentLocation )
960+ else ContentLocation (location )
961+ if location is not None
962+ else None
963+ )
964+
907965 for entry in state ["urls" ]:
908966 self .add (entry ["url" ], asset = entry ["asset" ], tag = entry ["tag" ])
909967
910- def __bool__ (self ):
968+ def __bool__ (self ) -> bool :
911969 """Allows the Apprise object to be wrapped in an 'if statement'.
912970
913971 True is returned if at least one service has been loaded.
914972 """
915973 return len (self ) > 0
916974
917- def __iter__ (self ):
975+ def __iter__ (self ) -> Iterator [ NotifyBase ] :
918976 """Returns an iterator to each of our servers loaded.
919977
920978 This includes those found inside configuration.
@@ -928,7 +986,7 @@ def __iter__(self):
928986 for s in self .servers
929987 ])
930988
931- def __len__ (self ):
989+ def __len__ (self ) -> int :
932990 """Returns the number of servers loaded; this includes those found
933991 within loaded configuration.
934992
0 commit comments