From f53205cdf147185e7001aaf9b0d724abc14dad7f Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 11 Oct 2016 21:12:40 +0300 Subject: revert most of the recent Pylint fixes I know better how to name my things. --- .pylintrc | 3 +-- bin/mutual_friends.py | 6 +++--- bin/online_sessions.py | 34 +++++++++++++++++----------------- bin/track_status.py | 14 +++++++------- vk/last_seen.py | 30 +++++++++++++++--------------- vk/platform.py | 20 ++++++++++---------- vk/tracking/db/record.py | 6 +++--- vk/tracking/db/timestamp.py | 30 +++++++++++++++--------------- vk/tracking/online_sessions.py | 24 ++++++++++++------------ vk/tracking/status_tracker.py | 34 +++++++++++++++++----------------- vk/user.py | 32 ++++++++++++++++---------------- 11 files changed, 116 insertions(+), 117 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4cb9bbf..2cca631 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,14 +1,13 @@ [MESSAGES CONTROL] #disable=old-ne-operator,filter-builtin-not-iterating,nonzero-method,long-builtin,unpacking-in-except,backtick,suppressed-message,setslice-method,round-builtin,coerce-builtin,input-builtin,raising-string,raw_input-builtin,apply-builtin,delslice-method,useless-suppression,hex-method,zip-builtin-not-iterating,range-builtin-not-iterating,intern-builtin,old-octal-literal,xrange-builtin,no-absolute-import,cmp-builtin,reduce-builtin,next-method-called,getslice-method,oct-method,reload-builtin,dict-view-method,file-builtin,long-suffix,parameter-unpacking,dict-iter-method,cmp-method,old-division,using-cmp-argument,buffer-builtin,old-raise-syntax,indexing-exception,unicode-builtin,unichr-builtin,coerce-method,basestring-builtin,map-builtin-not-iterating,metaclass-assignment,print-statement,import-star-module-level,standarderror-builtin,execfile-builtin -disable=duplicate-code,missing-docstring,multiple-imports,too-many-public-methods,too-few-public-methods +disable=duplicate-code,invalid-name,missing-docstring,multiple-imports,too-many-public-methods,too-few-public-methods [BASIC] #bad-functions=map,filter bad-functions= #good-names=i,j,k,ex,Run,_ -good-names=_,e,fd,i,n #bad-names=foo,bar,baz,toto,tutu,tata #name-group= #include-naming-hint=no diff --git a/bin/mutual_friends.py b/bin/mutual_friends.py index 29f92d9..8e6e584 100644 --- a/bin/mutual_friends.py +++ b/bin/mutual_friends.py @@ -70,11 +70,11 @@ class OutputFormat(Enum): else: raise NotImplementedError('unsupported output format: ' + str(self)) -def _parse_output_format(src): +def _parse_output_format(s): try: - return OutputFormat(src) + return OutputFormat(s) except ValueError: - raise argparse.ArgumentTypeError('invalid output format: ' + src) + raise argparse.ArgumentTypeError('invalid output format: ' + s) def _parse_args(args=sys.argv): parser = argparse.ArgumentParser( diff --git a/bin/online_sessions.py b/bin/online_sessions.py index a42e0dd..ac182e7 100644 --- a/bin/online_sessions.py +++ b/bin/online_sessions.py @@ -187,9 +187,9 @@ class BarChartBuilder: def get_value_labels(self): return self._get_value_axis().get_ticklabels() - def set_value_label_formatter(self, handler): + def set_value_label_formatter(self, fn): from matplotlib.ticker import FuncFormatter - self._get_value_axis().set_major_formatter(FuncFormatter(handler)) + self._get_value_axis().set_major_formatter(FuncFormatter(fn)) def set_integer_values_only(self): from matplotlib.ticker import MaxNLocator @@ -289,8 +289,8 @@ class OutputWriterPlot: return str(timedelta(seconds=seconds)) @staticmethod - def _duration_to_seconds(duration): - return duration.total_seconds() + def _duration_to_seconds(td): + return td.total_seconds() @staticmethod def _extract_labels(group_by, durations): @@ -350,34 +350,34 @@ class OutputFormat(Enum): def __str__(self): return self.value -def _parse_group_by(src): +def _parse_group_by(s): try: - return GroupBy(src) + return GroupBy(s) except ValueError: - raise argparse.ArgumentTypeError('invalid "group by" value: ' + src) + raise argparse.ArgumentTypeError('invalid "group by" value: ' + s) -def _parse_database_format(src): +def _parse_database_format(s): try: - return DatabaseFormat(src) + return DatabaseFormat(s) except ValueError: - raise argparse.ArgumentTypeError('invalid database format: ' + src) + raise argparse.ArgumentTypeError('invalid database format: ' + s) -def _parse_output_format(src): +def _parse_output_format(s): try: - return OutputFormat(src) + return OutputFormat(s) except ValueError: - raise argparse.ArgumentTypeError('invalid output format: ' + src) + raise argparse.ArgumentTypeError('invalid output format: ' + s) _DATE_RANGE_LIMIT_FORMAT = '%Y-%m-%dT%H:%M:%SZ' -def _parse_date_range_limit(src): +def _parse_date_range_limit(s): try: - timestamp = datetime.strptime(src, _DATE_RANGE_LIMIT_FORMAT) - return timestamp.replace(tzinfo=timezone.utc) + dt = datetime.strptime(s, _DATE_RANGE_LIMIT_FORMAT) + return dt.replace(tzinfo=timezone.utc) except ValueError: msg = 'invalid date range limit (must be in the \'{}\' format): {}' raise argparse.ArgumentTypeError( - msg.format(_DATE_RANGE_LIMIT_FORMAT, src)) + msg.format(_DATE_RANGE_LIMIT_FORMAT, s)) def _parse_args(args=sys.argv): parser = argparse.ArgumentParser( diff --git a/bin/track_status.py b/bin/track_status.py index e59b0e1..c221c53 100644 --- a/bin/track_status.py +++ b/bin/track_status.py @@ -12,20 +12,20 @@ from vk.tracking.db import Format as DatabaseFormat DEFAULT_TIMEOUT = StatusTracker.DEFAULT_TIMEOUT DEFAULT_DB_FORMAT = DatabaseFormat.CSV -def _parse_positive_integer(src): +def _parse_positive_integer(s): try: - n = int(src) + n = int(s) except ValueError: - raise argparse.ArgumentTypeError('must be a positive integer: ' + src) + raise argparse.ArgumentTypeError('must be a positive integer: ' + s) if n < 1: - raise argparse.ArgumentTypeError('must be a positive integer: ' + src) + raise argparse.ArgumentTypeError('must be a positive integer: ' + s) return n -def _parse_database_format(src): +def _parse_database_format(s): try: - return DatabaseFormat(src) + return DatabaseFormat(s) except ValueError: - raise argparse.ArgumentTypeError('invalid database format: ' + src) + raise argparse.ArgumentTypeError('invalid database format: ' + s) def _parse_args(args=sys.argv): parser = argparse.ArgumentParser( diff --git a/vk/last_seen.py b/vk/last_seen.py index 1753e12..5266940 100644 --- a/vk/last_seen.py +++ b/vk/last_seen.py @@ -11,23 +11,23 @@ from numbers import Integral, Real from .platform import Platform -def _parse_time(src): - if isinstance(src, datetime): - if src.tzinfo is None or src.tzinfo.utcoffset(src) is None: - src = src.replace(tzinfo=timezone.utc) - return src - elif isinstance(src, Real) or isinstance(src, Integral): - return datetime.fromtimestamp(src, tz=timezone.utc) +def _parse_time(x): + if isinstance(x, datetime): + 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): + return datetime.fromtimestamp(x, tz=timezone.utc) else: raise TypeError() -def _parse_platform(src): - if src in Platform: - return src - if isinstance(src, str): - return Platform.from_string(src) +def _parse_platform(x): + if x in Platform: + return x + if isinstance(x, str): + return Platform.from_string(x) else: - return Platform(src) + return Platform(x) class LastSeenField(Enum): TIME = 'time' @@ -85,8 +85,8 @@ class LastSeen(MutableMapping): def get_time(self): return self[LastSeenField.TIME] - def set_time(self, timestamp): - self[LastSeenField.TIME] = timestamp + def set_time(self, time): + self[LastSeenField.TIME] = time def has_platform(self): return LastSeenField.PLATFORM in self diff --git a/vk/platform.py b/vk/platform.py index 26f20dc..fa1e665 100644 --- a/vk/platform.py +++ b/vk/platform.py @@ -16,26 +16,26 @@ class Platform(Enum): WEB = 7 @staticmethod - def from_string(src): - return Platform(int(src)) + def from_string(s): + return Platform(int(s)) def __str__(self): return str(self.value) @staticmethod - def _uppercase_first_letter(text): - match = re.search(r'\w', text) - if match is None: - return text - return text[:match.start()] + match.group().upper() + text[match.end():] + def _uppercase_first_letter(s): + m = re.search(r'\w', s) + if m is None: + return s + return s[:m.start()] + m.group().upper() + s[m.end():] def get_descr_header(self): return self._uppercase_first_letter(_PLATFORM_DESCRIPTIONS[self]) def get_descr_text(self): - descr = _PLATFORM_DESCRIPTIONS[self] - descr = descr.replace('unrecognized', 'an unrecognized') - return 'the ' + descr + s = _PLATFORM_DESCRIPTIONS[self] + s = s.replace('unrecognized', 'an unrecognized') + return 'the ' + s def get_descr_text_capitalized(self): return self._uppercase_first_letter(self.get_descr_text()) diff --git a/vk/tracking/db/record.py b/vk/tracking/db/record.py index 6c000ab..c03c3ca 100644 --- a/vk/tracking/db/record.py +++ b/vk/tracking/db/record.py @@ -38,9 +38,9 @@ class Record(MutableMapping): def __setitem__(self, field, value): if field is LastSeenField.TIME: if isinstance(value, str): - value = Timestamp.from_string(value).impl + value = Timestamp.from_string(value).dt elif isinstance(value, Timestamp): - value = value.impl + value = value.dt elif isinstance(value, datetime): pass else: @@ -78,7 +78,7 @@ class Record(MutableMapping): def _update_last_seen_field(self, last_seen, field): if field is LastSeenField.TIME: - last_seen[field] = self[field].impl + last_seen[field] = self[field].dt else: last_seen[field] = self[field] diff --git a/vk/tracking/db/timestamp.py b/vk/tracking/db/timestamp.py index 0881fb3..b2219ca 100644 --- a/vk/tracking/db/timestamp.py +++ b/vk/tracking/db/timestamp.py @@ -11,25 +11,25 @@ class Timestamp: return datetime.utcnow() @staticmethod - def _is_timezone_aware(impl): - return impl.tzinfo is not None and impl.tzinfo.utcoffset(impl) is not None + def _is_timezone_aware(dt): + return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None @staticmethod - def _lose_timezone(impl): - if Timestamp._is_timezone_aware(impl): - return impl.astimezone(timezone.utc).replace(tzinfo=None) - return impl + def _lose_timezone(dt): + if Timestamp._is_timezone_aware(dt): + return dt.astimezone(timezone.utc).replace(tzinfo=None) + return dt - def __init__(self, impl=None): - if impl is None: - impl = self._new() - impl = impl.replace(microsecond=0) - impl = self._lose_timezone(impl) - self.impl = impl + def __init__(self, dt=None): + if dt is None: + dt = self._new() + dt = dt.replace(microsecond=0) + dt = self._lose_timezone(dt) + self.dt = dt @staticmethod - def from_string(src): - return Timestamp(datetime.strptime(src, '%Y-%m-%dT%H:%M:%SZ')) + def from_string(s): + return Timestamp(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')) def __str__(self): - return self.impl.isoformat() + 'Z' + return self.dt.isoformat() + 'Z' diff --git a/vk/tracking/online_sessions.py b/vk/tracking/online_sessions.py index 11d3196..204e1cc 100644 --- a/vk/tracking/online_sessions.py +++ b/vk/tracking/online_sessions.py @@ -99,20 +99,20 @@ class OnlineSessionEnumerator(MutableMapping): return by_hour @staticmethod - def _split_into_days(time_from, time_to): - while time_from.date() != time_to.date(): - next_day = time_from.date() + timedelta(days=1) - yield time_from.date(), next_day - time_from - time_from = next_day - yield time_to.date(), time_to - time_from + def _split_into_days(a, b): + while a.date() != b.date(): + next_day = a.date() + timedelta(days=1) + yield a.date(), next_day - a + a = next_day + yield b.date(), b - a @staticmethod - def _split_into_hours(time_from, time_to): - while time_from.date() != time_to.date() or time_from.hour != time_to.hour: - next_hour = time_from.replace(minute=0, second=0) + timedelta(hours=1) - yield time_from.hour, next_hour - time_from - time_from = next_hour - yield time_to.hour, time_to - time_from + def _split_into_hours(a, b): + while a.date() != b.date() or a.hour != b.hour: + next_hour = a.replace(minute=0, second=0) + timedelta(hours=1) + yield a.hour, next_hour - a + a = next_hour + yield b.hour, b - a def _process_database_record(self, record): return self._close_user_session(record.to_user()) diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py index d52af6a..d47de39 100644 --- a/vk/tracking/status_tracker.py +++ b/vk/tracking/status_tracker.py @@ -27,21 +27,21 @@ class StatusTracker: self.add_status_update_handler(writer.on_status_update) self.add_connection_error_handler(writer.on_connection_error) - def add_initial_status_handler(self, handler): - self._assert_is_callback(handler) - self._on_initial_status.append(handler) + def add_initial_status_handler(self, fn): + self._assert_is_callback(fn) + self._on_initial_status.append(fn) - def add_status_update_handler(self, handler): - self._assert_is_callback(handler) - self._on_status_update.append(handler) + def add_status_update_handler(self, fn): + self._assert_is_callback(fn) + self._on_status_update.append(fn) - def add_connection_error_handler(self, handler): - self._assert_is_callback(handler) - self._on_connection_error.append(handler) + def add_connection_error_handler(self, fn): + self._assert_is_callback(fn) + self._on_connection_error.append(fn) @staticmethod - def _assert_is_callback(handler): - if not isinstance(handler, Callable): + def _assert_is_callback(fn): + if not isinstance(fn, Callable): raise TypeError() _USER_FIELDS = UserField.DOMAIN, UserField.ONLINE, UserField.LAST_SEEN, @@ -50,16 +50,16 @@ class StatusTracker: return {user.get_uid(): user for user in self._api.users_get(uids, self._USER_FIELDS)} def _notify_status(self, user): - for handler in self._on_initial_status: - handler(user) + for fn in self._on_initial_status: + fn(user) def _notify_status_update(self, user): - for handler in self._on_status_update: - handler(user) + for fn in self._on_status_update: + fn(user) def _notify_connection_error(self, e): - for handler in self._on_connection_error: - handler(e) + for fn in self._on_connection_error: + fn(e) def _query_initial_status(self, uids): while True: diff --git a/vk/user.py b/vk/user.py index 6fae83d..f63f793 100644 --- a/vk/user.py +++ b/vk/user.py @@ -9,30 +9,30 @@ from enum import Enum from .last_seen import LastSeen -def _parse_last_seen(src): - if isinstance(src, LastSeen): - return src - elif isinstance(src, Mapping): - return LastSeen.from_api_response(src) +def _parse_last_seen(x): + if isinstance(x, LastSeen): + return x + elif isinstance(x, Mapping): + return LastSeen.from_api_response(x) else: raise TypeError() -def _parse_bool(src): - if isinstance(src, str): - if str(True) == src: +def _parse_bool(x): + if isinstance(x, str): + if str(True) == x: return True - elif str(False) == src: + elif str(False) == x: return False else: raise ValueError() else: - return bool(src) + return bool(x) -def _parse_hidden(src): - return _parse_bool(src) +def _parse_hidden(x): + return _parse_bool(x) -def _parse_online_flag(src): - return _parse_bool(src) +def _parse_online_flag(x): + return _parse_bool(x) class UserField(Enum): UID = 'uid' @@ -56,8 +56,8 @@ class DeactivationReason(Enum): def __str__(self): return self.value -def _parse_deactivated(src): - return DeactivationReason(src) +def _parse_deactivated(s): + return DeactivationReason(s) class User(Hashable, MutableMapping): @staticmethod -- cgit v1.2.3