Skip to content

Commit 3374773

Browse files
committed
ruff linting fix
1 parent ce8dbab commit 3374773

336 files changed

Lines changed: 4757 additions & 5575 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apprise/__init__.py

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# BSD 2-Clause License
32
#
43
# Apprise - Push Notification Library.
@@ -34,73 +33,85 @@
3433
__email__ = 'lead2gold@gmail.com'
3534
__status__ = 'Production'
3635

37-
from .common import NotifyType
38-
from .common import NOTIFY_TYPES
39-
from .common import NotifyImageSize
40-
from .common import NOTIFY_IMAGE_SIZES
41-
from .common import NotifyFormat
42-
from .common import NOTIFY_FORMATS
43-
from .common import OverflowMode
44-
from .common import OVERFLOW_MODES
45-
from .common import ConfigFormat
46-
from .common import CONFIG_FORMATS
47-
from .common import ContentIncludeMode
48-
from .common import CONTENT_INCLUDE_MODES
49-
from .common import ContentLocation
50-
from .common import CONTENT_LOCATIONS
51-
from .common import PersistentStoreMode
52-
from .common import PERSISTENT_STORE_MODES
53-
54-
from .url import URLBase
55-
from .url import PrivacyMode
56-
from .plugins.base import NotifyBase
57-
from .config.base import ConfigBase
58-
from .attachment.base import AttachBase
59-
from . import exception
60-
36+
from . import decorators, exception
6137
from .apprise import Apprise
62-
from .locale import AppriseLocale
63-
from .asset import AppriseAsset
64-
from .persistent_store import PersistentStore
65-
from .apprise_config import AppriseConfig
6638
from .apprise_attachment import AppriseAttachment
39+
from .apprise_config import AppriseConfig
40+
from .asset import AppriseAsset
41+
from .attachment.base import AttachBase
42+
from .common import (
43+
CONFIG_FORMATS,
44+
CONTENT_INCLUDE_MODES,
45+
CONTENT_LOCATIONS,
46+
NOTIFY_FORMATS,
47+
NOTIFY_IMAGE_SIZES,
48+
NOTIFY_TYPES,
49+
OVERFLOW_MODES,
50+
PERSISTENT_STORE_MODES,
51+
ConfigFormat,
52+
ContentIncludeMode,
53+
ContentLocation,
54+
NotifyFormat,
55+
NotifyImageSize,
56+
NotifyType,
57+
OverflowMode,
58+
PersistentStoreMode,
59+
)
60+
from .config.base import ConfigBase
61+
from .locale import AppriseLocale
62+
63+
# Inherit our logging with our additional entries added to it
64+
from .logger import LogCapture, logger, logging
6765
from .manager_attachment import AttachmentManager
6866
from .manager_config import ConfigurationManager
6967
from .manager_plugins import NotificationManager
70-
from . import decorators
71-
72-
# Inherit our logging with our additional entries added to it
73-
from .logger import logging
74-
from .logger import logger
75-
from .logger import LogCapture
68+
from .persistent_store import PersistentStore
69+
from .plugins.base import NotifyBase
70+
from .url import PrivacyMode, URLBase
7671

7772
# Set default logging handler to avoid "No handler found" warnings.
7873
logging.getLogger(__name__).addHandler(logging.NullHandler())
7974

8075
__all__ = [
76+
'CONFIG_FORMATS',
77+
'CONTENT_INCLUDE_MODES',
78+
'CONTENT_LOCATIONS',
79+
'NOTIFY_FORMATS',
80+
'NOTIFY_IMAGE_SIZES',
81+
'NOTIFY_TYPES',
82+
'OVERFLOW_MODES',
83+
'PERSISTENT_STORE_MODES',
8184
# Core
82-
'Apprise', 'AppriseAsset', 'AppriseConfig', 'AppriseAttachment', 'URLBase',
83-
'NotifyBase', 'ConfigBase', 'AttachBase', 'AppriseLocale',
84-
'PersistentStore',
85-
86-
# Exceptions
87-
'exception',
88-
85+
'Apprise',
86+
'AppriseAsset',
87+
'AppriseAttachment',
88+
'AppriseConfig',
89+
'AppriseLocale',
90+
'AttachBase',
91+
'AttachmentManager',
92+
'ConfigBase',
93+
'ConfigFormat',
94+
'ConfigurationManager',
95+
'ContentIncludeMode',
96+
'ContentLocation',
97+
'LogCapture',
98+
# Managers
99+
'NotificationManager',
100+
'NotifyBase',
101+
'NotifyFormat',
102+
'NotifyImageSize',
89103
# Reference
90-
'NotifyType', 'NotifyImageSize', 'NotifyFormat', 'OverflowMode',
91-
'NOTIFY_TYPES', 'NOTIFY_IMAGE_SIZES', 'NOTIFY_FORMATS', 'OVERFLOW_MODES',
92-
'ConfigFormat', 'CONFIG_FORMATS',
93-
'ContentIncludeMode', 'CONTENT_INCLUDE_MODES',
94-
'ContentLocation', 'CONTENT_LOCATIONS',
95-
'PersistentStoreMode', 'PERSISTENT_STORE_MODES',
104+
'NotifyType',
105+
'OverflowMode',
106+
'PersistentStore',
107+
'PersistentStoreMode',
96108
'PrivacyMode',
97-
98-
# Managers
99-
'NotificationManager', 'ConfigurationManager', 'AttachmentManager',
100-
109+
'URLBase',
101110
# Decorator
102111
'decorators',
103-
112+
# Exceptions
113+
'exception',
104114
# Logging
105-
'logging', 'logger', 'LogCapture',
115+
'logger',
116+
'logging',
106117
]

apprise/apprise.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# BSD 2-Clause License
32
#
43
# Apprise - Push Notification Library.
@@ -28,25 +27,23 @@
2827

2928
import asyncio
3029
import concurrent.futures as cf
31-
import os
3230
from itertools import chain
33-
from . import common
31+
import os
32+
33+
from . import __version__, common, plugins
34+
from .apprise_attachment import AppriseAttachment
35+
from .apprise_config import AppriseConfig
36+
from .asset import AppriseAsset
37+
from .config.base import ConfigBase
3438
from .conversion import convert_between
35-
from .utils.logic import is_exclusive_match
36-
from .utils.parse import parse_list, parse_urls
37-
from .utils.cwe312 import cwe312_url
38-
from .manager_plugins import NotificationManager
3939
from .emojis import apply_emojis
40-
from .logger import logger
41-
from .asset import AppriseAsset
42-
from .apprise_config import AppriseConfig
43-
from .apprise_attachment import AppriseAttachment
4440
from .locale import AppriseLocale
45-
from .config.base import ConfigBase
41+
from .logger import logger
42+
from .manager_plugins import NotificationManager
4643
from .plugins.base import NotifyBase
47-
48-
from . import plugins
49-
from . import __version__
44+
from .utils.cwe312 import cwe312_url
45+
from .utils.logic import is_exclusive_match
46+
from .utils.parse import parse_list, parse_urls
5047

5148
# Grant access to our Notification Manager Singleton
5249
N_MGR = NotificationManager()
@@ -70,7 +67,7 @@ def __init__(self, servers=None, asset=None, location=None, debug=False):
7067
"""
7168

7269
# Initialize a server list of URLs
73-
self.servers = list()
70+
self.servers = []
7471

7572
# Assigns an central asset object that will be later passed into each
7673
# notification plugin. Assets contain information such as the local
@@ -147,14 +144,14 @@ def instantiate(url, asset=None, tag=None, suppress_exceptions=True):
147144
logger.trace(
148145
'Invalid dictionary unpacked as:{}{}'.format(
149146
os.linesep, os.linesep.join(
150-
['{}="{}"'.format(k, v)
147+
[f'{k}="{v}"'
151148
for k, v in results.items()])))
152149
return None
153150

154151
logger.trace(
155152
'Dictionary unpacked as:{}{}'.format(
156153
os.linesep, os.linesep.join(
157-
['{}="{}"'.format(k, v) for k, v in results.items()])))
154+
[f'{k}="{v}"' for k, v in results.items()])))
158155

159156
# Otherwise we handle the invalid input specified
160157
else:
@@ -264,8 +261,7 @@ def add(self, servers, asset=None, tag=None):
264261

265262
elif not isinstance(servers, (tuple, set, list)):
266263
logger.error(
267-
"An invalid notification (type={}) was specified.".format(
268-
type(servers)))
264+
f"An invalid notification (type={type(servers)}) was specified.")
269265
return False
270266

271267
for _server in servers:
@@ -277,8 +273,7 @@ def add(self, servers, asset=None, tag=None):
277273

278274
elif not isinstance(_server, (str, dict)):
279275
logger.error(
280-
"An invalid notification (type={}) was specified.".format(
281-
type(_server)))
276+
f"An invalid notification (type={type(_server)}) was specified.")
282277
return_status = False
283278
continue
284279

@@ -469,13 +464,13 @@ def _create_notify_gen(self, body, title='',
469464

470465
except UnicodeDecodeError:
471466
msg = 'The content passed into Apprise was not of encoding ' \
472-
'type: {}'.format(self.asset.encoding)
467+
f'type: {self.asset.encoding}'
473468
logger.error(msg)
474469
raise TypeError(msg)
475470

476471
# Tracks conversions
477-
conversion_body_map = dict()
478-
conversion_title_map = dict()
472+
conversion_body_map = {}
473+
conversion_title_map = {}
479474

480475
# Prepare attachments if required
481476
if attach is not None and not isinstance(attach, AppriseAttachment):
@@ -510,7 +505,7 @@ def _create_notify_gen(self, body, title='',
510505
if key not in conversion_title_map:
511506

512507
# Prepare our title
513-
conversion_title_map[key] = '' if not title else title
508+
conversion_title_map[key] = title if title else ''
514509

515510
# Conversion of title only occurs for services where the title
516511
# is blended with the body (title_maxlen <= 0)
@@ -558,13 +553,13 @@ def _create_notify_gen(self, body, title='',
558553
conversion_title_map[key] = \
559554
apply_emojis(conversion_title_map[key])
560555

561-
kwargs = dict(
562-
body=conversion_body_map[key],
563-
title=conversion_title_map[key],
564-
notify_type=notify_type,
565-
attach=attach,
566-
body_format=body_format
567-
)
556+
kwargs = {
557+
'body': conversion_body_map[key],
558+
'title': conversion_title_map[key],
559+
'notify_type': notify_type,
560+
'attach': attach,
561+
'body_format': body_format
562+
}
568563
yield (server, kwargs)
569564

570565
@staticmethod
@@ -861,7 +856,7 @@ def __setstate__(self, state):
861856
"""
862857
Pickle Support loads()
863858
"""
864-
self.servers = list()
859+
self.servers = []
865860
self.asset = state['asset']
866861
self.locale = state['locale']
867862
self.location = state['location']

apprise/apprise.pyi

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
from typing import Any, Dict, List, Iterable, Iterator, Optional
1+
from collections.abc import Iterable, Iterator
2+
from typing import Any
23

3-
from . import (AppriseAsset, AppriseAttachment, AppriseConfig, ConfigBase,
4-
NotifyBase, NotifyFormat, NotifyType)
4+
from . import (
5+
AppriseAsset,
6+
AppriseAttachment,
7+
AppriseConfig,
8+
ConfigBase,
9+
NotifyBase,
10+
NotifyFormat,
11+
NotifyType,
12+
)
513
from .common import ContentLocation
614

715
_Server = Union[str, ConfigBase, NotifyBase, AppriseConfig]
8-
_Servers = Union[_Server, Dict[Any, _Server], Iterable[_Server]]
16+
_Servers = Union[_Server, dict[Any, _Server], Iterable[_Server]]
917
# Can't define this recursively as mypy doesn't support recursive types:
1018
# https://github.com/python/mypy/issues/731
1119
_Tag = Union[str, Iterable[Union[str, Iterable[str]]]]
@@ -14,22 +22,22 @@ class Apprise:
1422
def __init__(
1523
self,
1624
servers: _Servers = ...,
17-
asset: Optional[AppriseAsset] = ...,
18-
location: Optional[ContentLocation] = ...,
25+
asset: AppriseAsset | None = ...,
26+
location: ContentLocation | None = ...,
1927
debug: bool = ...
2028
) -> None: ...
2129
@staticmethod
2230
def instantiate(
23-
url: Union[str, Dict[str, NotifyBase]],
24-
asset: Optional[AppriseAsset] = ...,
25-
tag: Optional[_Tag] = ...,
31+
url: Union[str, dict[str, NotifyBase]],
32+
asset: AppriseAsset | None = ...,
33+
tag: _Tag | None = ...,
2634
suppress_exceptions: bool = ...
2735
) -> NotifyBase: ...
2836
def add(
2937
self,
3038
servers: _Servers = ...,
31-
asset: Optional[AppriseAsset] = ...,
32-
tag: Optional[_Tag] = ...
39+
asset: AppriseAsset | None = ...,
40+
tag: _Tag | None = ...
3341
) -> bool: ...
3442
def clear(self) -> None: ...
3543
def find(self, tag: str = ...) -> Iterator[Apprise]: ...
@@ -40,8 +48,8 @@ class Apprise:
4048
notify_type: NotifyType = ...,
4149
body_format: NotifyFormat = ...,
4250
tag: _Tag = ...,
43-
attach: Optional[AppriseAttachment] = ...,
44-
interpret_escapes: Optional[bool] = ...
51+
attach: AppriseAttachment | None = ...,
52+
interpret_escapes: bool | None = ...
4553
) -> bool: ...
4654
async def async_notify(
4755
self,
@@ -50,13 +58,13 @@ class Apprise:
5058
notify_type: NotifyType = ...,
5159
body_format: NotifyFormat = ...,
5260
tag: _Tag = ...,
53-
attach: Optional[AppriseAttachment] = ...,
54-
interpret_escapes: Optional[bool] = ...
61+
attach: AppriseAttachment | None = ...,
62+
interpret_escapes: bool | None = ...
5563
) -> bool: ...
56-
def details(self, lang: Optional[str] = ...) -> Dict[str, Any]: ...
64+
def details(self, lang: str | None = ...) -> dict[str, Any]: ...
5765
def urls(self, privacy: bool = ...) -> Iterable[str]: ...
5866
def pop(self, index: int) -> ConfigBase: ...
5967
def __getitem__(self, index: int) -> ConfigBase: ...
6068
def __bool__(self) -> bool: ...
6169
def __iter__(self) -> Iterator[ConfigBase]: ...
62-
def __len__(self) -> int: ...
70+
def __len__(self) -> int: ...

0 commit comments

Comments
 (0)