diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2018-03-03 15:40:10 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2018-03-03 15:40:10 +0300 |
commit | 96f1356aeafbdc026846cdbe1bcfcbbbd0ab3a7c (patch) | |
tree | 271e85f93792247725cd19f8064b65c7346acb68 | |
parent | new platform, "VK Mobile" (diff) | |
download | vk-scripts-96f1356aeafbdc026846cdbe1bcfcbbbd0ab3a7c.tar.gz vk-scripts-96f1356aeafbdc026846cdbe1bcfcbbbd0ab3a7c.zip |
fix Pylint warnings
-rw-r--r-- | vk/api.py | 10 | ||||
-rw-r--r-- | vk/last_seen.py | 11 | ||||
-rw-r--r-- | vk/tracking/db/backend/log.py | 3 | ||||
-rw-r--r-- | vk/tracking/db/record.py | 5 | ||||
-rw-r--r-- | vk/tracking/status_tracker.py | 3 | ||||
-rw-r--r-- | vk/user.py | 3 |
6 files changed, 16 insertions, 19 deletions
@@ -33,7 +33,7 @@ def _filter_empty_params(params, empty_params=False): def _build_url(scheme, host, path, params=None, empty_params=False): if params is None: params = {} - if isinstance(params, Mapping) or isinstance(params, Iterable): + if isinstance(params, (Iterable, Mapping)): params = _filter_empty_params(params, empty_params) params = urllib.parse.urlencode(params) elif isinstance(params, str): @@ -46,10 +46,9 @@ def _build_url(scheme, host, path, params=None, empty_params=False): def _join_param_values(values): if isinstance(values, str): return values - elif isinstance(values, Iterable): + if isinstance(values, Iterable): return ','.join(map(str, values)) - else: - return values + return values def _join_path(base, url): if not base.endswith('/'): @@ -113,7 +112,8 @@ class API: except (ConnectionError, URLError) as e: raise vk.error.APIConnectionError(str(e)) from e - def _filter_response_with_users(self, user_list, deactivated_users=True): + @staticmethod + def _filter_response_with_users(user_list, deactivated_users=True): user_list = map(User.from_api_response, user_list) if deactivated_users: return user_list diff --git a/vk/last_seen.py b/vk/last_seen.py index 5266940..25975f2 100644 --- a/vk/last_seen.py +++ b/vk/last_seen.py @@ -16,18 +16,16 @@ def _parse_time(x): if x.tzinfo is None or x.tzinfo.utcoffset(x) is None: x = x.replace(tzinfo=timezone.utc) return x - elif isinstance(x, Real) or isinstance(x, Integral): + if isinstance(x, (Integral, Real)): return datetime.fromtimestamp(x, tz=timezone.utc) - else: - raise TypeError() + raise TypeError() def _parse_platform(x): if x in Platform: return x if isinstance(x, str): return Platform.from_string(x) - else: - return Platform(x) + return Platform(x) class LastSeenField(Enum): TIME = 'time' @@ -69,8 +67,7 @@ class LastSeen(MutableMapping): def parse(field, value): if field in LastSeen._FIELD_PARSERS: return LastSeen._FIELD_PARSERS[field](value) - else: - return LastSeen._DEFAULT_FIELD_PARSER(value) + return LastSeen._DEFAULT_FIELD_PARSER(value) _FIELD_PARSERS = { LastSeenField.TIME: _parse_time, diff --git a/vk/tracking/db/backend/log.py b/vk/tracking/db/backend/log.py index 1ea009b..814cabc 100644 --- a/vk/tracking/db/backend/log.py +++ b/vk/tracking/db/backend/log.py @@ -70,8 +70,7 @@ class Writer(meta.Writer): def _format_user(user): if user.has_last_name(): return '{} {}'.format(user.get_first_name(), user.get_last_name()) - else: - return '{}'.format(user.get_first_name()) + return '{}'.format(user.get_first_name()) @staticmethod def _format_user_is_online(user): diff --git a/vk/tracking/db/record.py b/vk/tracking/db/record.py index c03c3ca..dfd47c6 100644 --- a/vk/tracking/db/record.py +++ b/vk/tracking/db/record.py @@ -7,10 +7,11 @@ from collections import OrderedDict from collections.abc import MutableMapping from datetime import datetime -from .timestamp import Timestamp from vk.last_seen import LastSeen, LastSeenField from vk.user import User, UserField +from .timestamp import Timestamp + class Record(MutableMapping): FIELDS = ( UserField.UID, @@ -95,6 +96,6 @@ class Record(MutableMapping): self._update_user_field(user, field) else: assert False - if len(last_seen): + if last_seen: user.set_last_seen(last_seen) return user diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py index 0dba0f9..e1a3216 100644 --- a/vk/tracking/status_tracker.py +++ b/vk/tracking/status_tracker.py @@ -47,7 +47,8 @@ class StatusTracker: _USER_FIELDS = UserField.DOMAIN, UserField.ONLINE, UserField.LAST_SEEN, def _query_status(self, uids): - return {user.get_uid(): user for user in self._api.users_get(uids, self._USER_FIELDS, deactivated_users=False)} + user_list = self._api.users_get(uids, self._USER_FIELDS, deactivated_users=False) + return {user.get_uid(): user for user in user_list} def _notify_status(self, user): for fn in self._on_initial_status: @@ -98,8 +98,7 @@ class User(Hashable, MutableMapping): def parse(field, value): if field in User._FIELD_PARSERS: return User._FIELD_PARSERS[field](value) - else: - return User._DEFAULT_FIELD_PARSER(value) + return User._DEFAULT_FIELD_PARSER(value) _FIELD_PARSERS = { UserField.UID: int, |