From 93c7aef433b9ea634855fe28288e4058276e3887 Mon Sep 17 00:00:00 2001 From: Ryan Young Date: Mon, 19 Jul 2021 13:26:38 -0700 Subject: [PATCH] Added limited type stubs for mypy (#402) --- apprise/Apprise.pyi | 63 +++++++++++++++++++++++++++++++ apprise/AppriseAsset.pyi | 34 +++++++++++++++++ apprise/AppriseAttachment.pyi | 38 +++++++++++++++++++ apprise/AppriseConfig.pyi | 49 ++++++++++++++++++++++++ apprise/URLBase.pyi | 16 ++++++++ apprise/attachment/AttachBase.pyi | 37 ++++++++++++++++++ apprise/common.pyi | 15 ++++++++ apprise/config/ConfigBase.pyi | 3 ++ apprise/plugins/NotifyBase.pyi | 1 + apprise/py.typed | 0 10 files changed, 256 insertions(+) create mode 100644 apprise/Apprise.pyi create mode 100644 apprise/AppriseAsset.pyi create mode 100644 apprise/AppriseAttachment.pyi create mode 100644 apprise/AppriseConfig.pyi create mode 100644 apprise/URLBase.pyi create mode 100644 apprise/attachment/AttachBase.pyi create mode 100644 apprise/common.pyi create mode 100644 apprise/config/ConfigBase.pyi create mode 100644 apprise/plugins/NotifyBase.pyi create mode 100644 apprise/py.typed diff --git a/apprise/Apprise.pyi b/apprise/Apprise.pyi new file mode 100644 index 00000000..919d370d --- /dev/null +++ b/apprise/Apprise.pyi @@ -0,0 +1,63 @@ +from typing import Any, Dict, List, Iterable, Iterator, Optional + +from . import (AppriseAsset, AppriseAttachment, AppriseConfig, ConfigBase, + NotifyBase, NotifyFormat, NotifyType) +from .common import ContentLocation + +_Server = Union[str, ConfigBase, NotifyBase, AppriseConfig] +_Servers = Union[_Server, Dict[Any, _Server], Iterable[_Server]] +# Can't define this recursively as mypy doesn't support recursive types: +# https://github.com/python/mypy/issues/731 +_Tag = Union[str, Iterable[Union[str, Iterable[str]]]] + +class Apprise: + def __init__( + self, + servers: _Servers = ..., + asset: Optional[AppriseAsset] = ..., + location: Optional[ContentLocation] = ..., + debug: bool = ... + ) -> None: ... + @staticmethod + def instantiate( + url: Union[str, Dict[str, NotifyBase]], + asset: Optional[AppriseAsset] = ..., + tag: Optional[_Tag] = ..., + suppress_exceptions: bool = ... + ) -> NotifyBase: ... + def add( + self, + servers: _Servers = ..., + asset: Optional[AppriseAsset] = ..., + tag: Optional[_Tag] = ... + ) -> bool: ... + def clear(self) -> None: ... + def find(self, tag: str = ...) -> Iterator[Apprise]: ... + def notify( + self, + body: str, + title: str = ..., + notify_type: NotifyType = ..., + body_format: NotifyFormat = ..., + tag: _Tag = ..., + attach: Optional[AppriseAttachment] = ..., + interpret_escapes: Optional[bool] = ... + ) -> bool: ... + async def async_notify( + self, + body: str, + title: str = ..., + notify_type: NotifyType = ..., + body_format: NotifyFormat = ..., + tag: _Tag = ..., + attach: Optional[AppriseAttachment] = ..., + interpret_escapes: Optional[bool] = ... + ) -> bool: ... + def details(self, lang: Optional[str] = ...) -> Dict[str, Any]: ... + def urls(self, privacy: bool = ...) -> Iterable[str]: ... + def pop(self, index: int) -> ConfigBase: ... + def __getitem__(self, index: int) -> ConfigBase: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... + def __iter__(self) -> Iterator[ConfigBase]: ... + def __len__(self) -> int: ... \ No newline at end of file diff --git a/apprise/AppriseAsset.pyi b/apprise/AppriseAsset.pyi new file mode 100644 index 00000000..08303341 --- /dev/null +++ b/apprise/AppriseAsset.pyi @@ -0,0 +1,34 @@ +from typing import Dict, Optional + +from . import NotifyFormat, NotifyType + +class AppriseAsset: + app_id: str + app_desc: str + app_url: str + html_notify_map: Dict[NotifyType, str] + default_html_color: str + default_extension: str + theme: Optional[str] + image_url_mask: str + image_url_logo: str + image_path_mask: Optional[str] + body_format: Optional[NotifyFormat] + async_mode: bool + interpret_escapes: bool + def __init__( + self, + app_id: str = ..., + app_desc: str = ..., + app_url: str = ..., + html_notify_map: Dict[NotifyType, str] = ..., + default_html_color: str = ..., + default_extension: str = ..., + theme: Optional[str] = ..., + image_url_mask: str = ..., + image_url_logo: str = ..., + image_path_mask: Optional[str] = ..., + body_format: Optional[NotifyFormat] = ..., + async_mode: bool = ..., + interpret_escapes: bool = ... + ) -> None: ... \ No newline at end of file diff --git a/apprise/AppriseAttachment.pyi b/apprise/AppriseAttachment.pyi new file mode 100644 index 00000000..d68eccc1 --- /dev/null +++ b/apprise/AppriseAttachment.pyi @@ -0,0 +1,38 @@ +from typing import Any, Iterable, Optional, Union + +from . import AppriseAsset, ContentLocation +from .attachment import AttachBase + +_Attachment = Union[str, AttachBase] +_Attachments = Iterable[_Attachment] + +class AppriseAttachment: + def __init__( + self, + paths: Optional[_Attachments] = ..., + asset: Optional[AppriseAttachment] = ..., + cache: bool = ..., + location: Optional[ContentLocation] = ..., + **kwargs: Any + ) -> None: ... + def add( + self, + attachments: _Attachments, + asset: Optional[AppriseAttachment] = ..., + cache: Optional[bool] = ... + ) -> bool: ... + @staticmethod + def instantiate( + url: str, + asset: Optional[AppriseAsset] = ..., + cache: Optional[bool] = ..., + suppress_exceptions: bool = ... + ) -> NotifyBase: ... + def clear(self) -> None: ... + def size(self) -> int: ... + def pop(self, index: int = ...) -> AttachBase: ... + def __getitem__(self, index: int) -> AttachBase: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... + def __iter__(self) -> Iterator[AttachBase]: ... + def __len__(self) -> int: ... \ No newline at end of file diff --git a/apprise/AppriseConfig.pyi b/apprise/AppriseConfig.pyi new file mode 100644 index 00000000..36fa9c06 --- /dev/null +++ b/apprise/AppriseConfig.pyi @@ -0,0 +1,49 @@ +from typing import Any, Iterable, Iterator, List, Optional, Union + +from . import AppriseAsset, NotifyBase +from .config import ConfigBase + +_Configs = Union[ConfigBase, str, Iterable[str]] + +class AppriseConfig: + def __init__( + self, + paths: Optional[_Configs] = ..., + asset: Optional[AppriseAsset] = ..., + cache: bool = ..., + recursion: int = ..., + insecure_includes: bool = ..., + **kwargs: Any + ) -> None: ... + def add( + self, + configs: _Configs, + asset: Optional[AppriseAsset] = ..., + cache: bool = ..., + recursion: Optional[bool] = ..., + insecure_includes: Optional[bool] = ... + ) -> bool: ... + def add_config( + self, + content: str, + asset: Optional[AppriseAsset] = ..., + tag: Optional[str] = ..., + format: Optional[str] = ..., + recursion: Optional[int] = ..., + insecure_includes: Optional[bool] = ... + ) -> bool: ... + def servers(self, tag: str = ..., *args: Any, **kwargs: Any) -> List[ConfigBase]: ... + def instantiate( + url: str, + asset: Optional[AppriseAsset] = ..., + tag: Optional[str] = ..., + cache: Optional[bool] = ... + ) -> NotifyBase: ... + def clear(self) -> None: ... + def server_pop(self, index: int) -> ConfigBase: ... + def pop(self, index: int = ...) -> ConfigBase: ... + def __getitem__(self, index: int) -> ConfigBase: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... + def __iter__(self) -> Iterator[ConfigBase]: ... + def __len__(self) -> int: ... \ No newline at end of file diff --git a/apprise/URLBase.pyi b/apprise/URLBase.pyi new file mode 100644 index 00000000..91588574 --- /dev/null +++ b/apprise/URLBase.pyi @@ -0,0 +1,16 @@ +from logging import logger +from typing import Any, Iterable, Set, Optional + +class URLBase: + service_name: Optional[str] + protocol: Optional[str] + secure_protocol: Optional[str] + request_rate_per_sec: int + socket_connect_timeout: float + socket_read_timeout: float + tags: Set[str] + verify_certificate: bool + logger: logger + def url(self, privacy: bool = ..., *args: Any, **kwargs: Any) -> str: ... + def __contains__(self, tags: Iterable[str]) -> bool: ... + def __str__(self) -> str: ... \ No newline at end of file diff --git a/apprise/attachment/AttachBase.pyi b/apprise/attachment/AttachBase.pyi new file mode 100644 index 00000000..9b8eb02a --- /dev/null +++ b/apprise/attachment/AttachBase.pyi @@ -0,0 +1,37 @@ +from typing import Any, Dict, Optional + +from .. import ContentLocation + +class AttachBase: + max_detect_buffer_size: int + unknown_mimetype: str + unknown_filename: str + unknown_filename_extension: str + strict: bool + max_file_size: int + location: ContentLocation + template_args: Dict[str, Any] + def __init__( + self, + name: Optional[str] = ..., + mimetype: Optional[str] = ..., + cache: Optional[bool] = ..., + **kwargs: Any + ) -> None: ... + @property + def path(self) -> Optional[str]: ... + @property + def name(self) -> Optional[str]: ... + @property + def mimetype(self) -> Optional[str]: ... + def exists(self) -> bool: ... + def invalidate(self) -> None: ... + def download(self) -> bool: ... + @staticmethod + def parse_url( + url: str, + verify_host: bool = ... + ) -> Dict[str, Any]: ... + def __len__(self) -> int: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... \ No newline at end of file diff --git a/apprise/common.pyi b/apprise/common.pyi new file mode 100644 index 00000000..76957318 --- /dev/null +++ b/apprise/common.pyi @@ -0,0 +1,15 @@ +class NotifyType: + INFO: NotifyType + SUCCESS: NotifyType + WARNING: NotifyType + FAILURE: NotifyType + +class NotifyFormat: + TEXT: NotifyFormat + HTML: NotifyFormat + MARKDOWN: NotifyFormat + +class ContentLocation: + LOCAL: ContentLocation + HOSTED: ContentLocation + INACCESSIBLE: ContentLocation \ No newline at end of file diff --git a/apprise/config/ConfigBase.pyi b/apprise/config/ConfigBase.pyi new file mode 100644 index 00000000..abff1204 --- /dev/null +++ b/apprise/config/ConfigBase.pyi @@ -0,0 +1,3 @@ +from .. import URLBase + +class ConfigBase(URLBase): ... \ No newline at end of file diff --git a/apprise/plugins/NotifyBase.pyi b/apprise/plugins/NotifyBase.pyi new file mode 100644 index 00000000..9cf3e404 --- /dev/null +++ b/apprise/plugins/NotifyBase.pyi @@ -0,0 +1 @@ +class NotifyBase: ... \ No newline at end of file diff --git a/apprise/py.typed b/apprise/py.typed new file mode 100644 index 00000000..e69de29b