From 44689af035cb42c7192a55d86e81e8ecf58f3d95 Mon Sep 17 00:00:00 2001 From: Andrei Zbikowski Date: Fri, 27 Oct 2017 18:06:39 -0700 Subject: [PATCH] [QOL] Flake8 CI and Fixes (#61) * Add flake8 to travis * Various flake8 fixes * dont * Only test against 2.7 / 3.6 I really don't care about 3.3/3.4/3.5 * Fix usage of unicode --- .flake8 | 3 +++ .travis.yml | 10 +++++----- disco/api/client.py | 34 ++++++++++++++++++++++++---------- disco/api/http.py | 4 ++-- disco/bot/bot.py | 6 +++--- disco/bot/command.py | 7 ++++--- disco/bot/parser.py | 20 +++++++++++++++----- disco/bot/storage.py | 8 ++++---- disco/client.py | 4 ++-- disco/gateway/client.py | 10 +++++----- disco/gateway/events.py | 2 +- disco/gateway/ipc.py | 2 +- disco/gateway/sharder.py | 18 ++++++++++++------ disco/state.py | 4 ++-- disco/types/__init__.py | 24 ++++++++++++++++++------ disco/types/base.py | 6 +++--- disco/types/channel.py | 6 +++--- disco/types/guild.py | 16 ++++++++-------- disco/types/message.py | 2 +- disco/types/user.py | 4 ++-- disco/types/webhook.py | 11 ++++++++++- disco/util/hashmap.py | 2 +- disco/util/limiter.py | 1 - disco/util/logging.py | 2 +- disco/voice/__init__.py | 8 +++++--- disco/voice/client.py | 8 ++++---- disco/voice/opus.py | 2 +- disco/voice/playable.py | 4 ++-- disco/voice/player.py | 2 +- tests/types/embeds.py | 2 -- 30 files changed, 143 insertions(+), 89 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..09513de --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 120 +ignore=C408,C815,A003 diff --git a/.travis.yml b/.travis.yml index ec028e6..bf33927 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,12 @@ cache: pip python: - '2.7' - - '3.3' - - '3.4' - - '3.5' - '3.6' install: - - pip install -U pip setuptools pytest + - pip install -U pip setuptools + - pip install -U pytest flake8-tuple flake8-quotes flake8-comprehensions flake8-commas flake8-builtins -script: 'python setup.py test' +script: + - python setup.py test + - flake8 disco/ diff --git a/disco/api/client.py b/disco/api/client.py index fa738c8..04214b3 100644 --- a/disco/api/client.py +++ b/disco/api/client.py @@ -34,7 +34,7 @@ def _reason_header(value): class Responses(list): def rate_limited_duration(self): - return sum([i.rate_limited_duration for i in self]) + return sum(i.rate_limited_duration for i in self) @property def rate_limited(self): @@ -128,7 +128,7 @@ class APIClient(LoggingClass): around=around, before=before, after=after, - limit=limit + limit=limit, )) return Message.create_map(self.client, r.json()) @@ -137,8 +137,16 @@ class APIClient(LoggingClass): r = self.http(Routes.CHANNELS_MESSAGES_GET, dict(channel=channel, message=message)) return Message.create(self.client, r.json()) - def channels_messages_create(self, channel, content=None, nonce=None, tts=False, - attachment=None, attachments=[], embed=None, sanitize=False): + def channels_messages_create( + self, + channel, + content=None, + nonce=None, + tts=False, + attachment=None, + attachments=[], + embed=None, + sanitize=False): payload = { 'nonce': nonce, @@ -173,7 +181,7 @@ class APIClient(LoggingClass): Routes.CHANNELS_MESSAGES_CREATE, dict(channel=channel), data={'payload_json': json.dumps(payload)}, - files=files + files=files, ) else: r = self.http(Routes.CHANNELS_MESSAGES_CREATE, dict(channel=channel), json=payload) @@ -232,7 +240,7 @@ class APIClient(LoggingClass): def channels_permissions_delete(self, channel, permission, reason=None): self.http( Routes.CHANNELS_PERMISSIONS_DELETE, - dict(channel=channel, permission=permission), headers=_reason_header(reason) + dict(channel=channel, permission=permission), headers=_reason_header(reason), ) def channels_invites_list(self, channel): @@ -244,7 +252,7 @@ class APIClient(LoggingClass): 'max_age': max_age, 'max_uses': max_uses, 'temporary': temporary, - 'unique': unique + 'unique': unique, }, headers=_reason_header(reason)) return Invite.create(self.client, r.json()) @@ -285,7 +293,8 @@ class APIClient(LoggingClass): r = self.http(Routes.GUILDS_CHANNELS_LIST, dict(guild=guild)) return Channel.create_hash(self.client, 'id', r.json(), guild_id=guild) - def guilds_channels_create(self, + def guilds_channels_create( + self, guild, channel_type, name, @@ -379,7 +388,9 @@ class APIClient(LoggingClass): r = self.http(Routes.GUILDS_ROLES_LIST, dict(guild=guild)) return Role.create_map(self.client, r.json(), guild_id=guild) - def guilds_roles_create(self, guild, + def guilds_roles_create( + self, + guild, name=None, permissions=None, color=None, @@ -404,7 +415,10 @@ class APIClient(LoggingClass): r = self.http(Routes.GUILDS_ROLES_MODIFY_BATCH, dict(guild=guild), json=roles, headers=_reason_header(reason)) return Role.create_map(self.client, r.json(), guild_id=guild) - def guilds_roles_modify(self, guild, role, + def guilds_roles_modify( + self, + guild, + role, name=None, hoist=None, color=None, diff --git a/disco/api/http.py b/disco/api/http.py index 6cea9c5..8bffb0d 100644 --- a/disco/api/http.py +++ b/disco/api/http.py @@ -159,7 +159,7 @@ class APIException(Exception): self.errors = {} if self.retries: - self.msg += " after {} retries".format(self.retries) + self.msg += ' after {} retries'.format(self.retries) # Try to decode JSON, and extract params try: @@ -298,7 +298,7 @@ class HTTPClient(LoggingClass): backoff = self.random_backoff() self.log.warning('Request to `{}` failed with code {}, retrying after {}s ({})'.format( - url, r.status_code, backoff, r.content + url, r.status_code, backoff, r.content, )) gevent.sleep(backoff) diff --git a/disco/bot/bot.py b/disco/bot/bot.py index f841dd3..5419c4d 100644 --- a/disco/bot/bot.py +++ b/disco/bot/bot.py @@ -217,7 +217,7 @@ class Bot(LoggingClass): Called when a plugin is loaded/unloaded to recompute internal state. """ if self.config.commands_group_abbrev: - groups = set(command.group for command in self.commands if command.group) + groups = {command.group for command in self.commands if command.group} self.group_abbrev = self.compute_group_abbrev(groups) self.compute_command_matches_re() @@ -293,7 +293,7 @@ class Bot(LoggingClass): mention_rules.get('user', True) and mention_direct, mention_rules.get('everyone', False) and mention_everyone, mention_rules.get('role', False) and any(mention_roles), - msg.channel.is_dm + msg.channel.is_dm, )): return [] @@ -375,7 +375,7 @@ class Bot(LoggingClass): self.config.commands_require_mention, self.config.commands_mention_rules, self.config.commands_prefix, - msg + msg, )) if not len(commands): diff --git a/disco/bot/command.py b/disco/bot/command.py index d17a8fb..75904b9 100644 --- a/disco/bot/command.py +++ b/disco/bot/command.py @@ -163,7 +163,8 @@ class Command(object): def get_docstring(self): return (self.func.__doc__ or '').format(**self.context) - def update(self, + def update( + self, args=None, level=None, aliases=None, @@ -266,7 +267,7 @@ class Command(object): group = self.group + ' ' return ('^{}({})' if grouped else '^{}(?:{})').format( group, - '|'.join(self.triggers) + '|'.join(self.triggers), ) + (ARGS_REGEX if grouped else ARGS_UNGROUPED_REGEX) def execute(self, event): @@ -287,7 +288,7 @@ class Command(object): event.name, self.args.required_length, self.raw_args, - len(event.args) + len(event.args), )) try: diff --git a/disco/bot/parser.py b/disco/bot/parser.py index fe2d90c..bc9572f 100644 --- a/disco/bot/parser.py +++ b/disco/bot/parser.py @@ -5,11 +5,20 @@ import copy # Regex which splits out argument parts PARTS_RE = re.compile('(\<|\[|\{)((?:\w+|\:|\||\.\.\.| (?:[0-9]+))+)(?:\>|\]|\})') -BOOL_OPTS = {'yes': True, 'no': False, 'true': True, 'False': False, '1': True, '0': False} +BOOL_OPTS = { + 'yes': True, + 'no': False, + 'true': True, + 'False': False, + '1': True, + '0': False, + 'on': True, + 'off': False, +} # Mapping of types TYPE_MAP = { - 'str': lambda ctx, data: str(data) if six.PY3 else unicode(data), + 'str': lambda ctx, data: six.text_type(data), 'int': lambda ctx, data: int(data), 'float': lambda ctx, data: float(data), 'snowflake': lambda ctx, data: int(data), @@ -21,6 +30,7 @@ def to_bool(ctx, data): return BOOL_OPTS[data] raise TypeError + TYPE_MAP['bool'] = to_bool @@ -190,9 +200,9 @@ class ArgumentSet(object): for idx, r in enumerate(raw): try: raw[idx] = self.convert(ctx, arg.types, r) - except: + except Exception: raise ArgumentError(u'cannot convert `{}` to `{}`'.format( - r, ', '.join(arg.types) + r, ', '.join(arg.types), )) if arg.count == 1: @@ -217,4 +227,4 @@ class ArgumentSet(object): """ The number of required arguments to compile this set/specificaiton. """ - return sum([i.true_count for i in self.args if i.required]) + return sum(i.true_count for i in self.args if i.required) diff --git a/disco/bot/storage.py b/disco/bot/storage.py index de81553..c02df4a 100644 --- a/disco/bot/storage.py +++ b/disco/bot/storage.py @@ -70,20 +70,20 @@ class Storage(object): def guild(self, key): return ContextAwareProxy( - lambda: self['_g{}:{}'.format(self._ctx['guild'].id, key)] + lambda: self['_g{}:{}'.format(self._ctx['guild'].id, key)], ) def channel(self, key): return ContextAwareProxy( - lambda: self['_c{}:{}'.format(self._ctx['channel'].id, key)] + lambda: self['_c{}:{}'.format(self._ctx['channel'].id, key)], ) def plugin(self, key): return ContextAwareProxy( - lambda: self['_p{}:{}'.format(self._ctx['plugin'].name, key)] + lambda: self['_p{}:{}'.format(self._ctx['plugin'].name, key)], ) def user(self, key): return ContextAwareProxy( - lambda: self['_u{}:{}'.format(self._ctx['user'].id, key)] + lambda: self['_u{}:{}'.format(self._ctx['user'].id, key)], ) diff --git a/disco/client.py b/disco/client.py index 9e0c30e..3374282 100644 --- a/disco/client.py +++ b/disco/client.py @@ -40,7 +40,7 @@ class ClientConfig(Config): should be either 'json' or 'etf'. """ - token = "" + token = '' shard_id = 0 shard_count = 1 max_reconnects = 5 @@ -100,7 +100,7 @@ class Client(LoggingClass): 'client': self, 'state': self.state, 'api': self.api, - 'gw': self.gw + 'gw': self.gw, } self.manhole = DiscoBackdoorServer(self.config.manhole_bind, diff --git a/disco/gateway/client.py b/disco/gateway/client.py index bb44a94..a11d27f 100644 --- a/disco/gateway/client.py +++ b/disco/gateway/client.py @@ -136,7 +136,7 @@ class GatewayClient(LoggingClass): self.ws.emitter.on('on_close', self.on_close) self.ws.emitter.on('on_message', self.on_message) - self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) + self.ws.run_forever(sslopt={'cert_reqs': ssl.CERT_NONE}) def on_message(self, msg): if self.zlib_stream_enabled: @@ -157,11 +157,11 @@ class GatewayClient(LoggingClass): # Detect zlib and decompress is_erlpack = ((six.PY2 and ord(msg[0]) == 131) or (six.PY3 and msg[0] == 131)) if msg[0] != '{' and not is_erlpack: - msg = zlib.decompress(msg, 15, TEN_MEGABYTES).decode("utf-8") + msg = zlib.decompress(msg, 15, TEN_MEGABYTES).decode('utf-8') try: data = self.encoder.decode(msg) - except: + except Exception: self.log.exception('Failed to parse gateway message: ') return @@ -188,7 +188,7 @@ class GatewayClient(LoggingClass): self.send(OPCode.RESUME, { 'token': self.client.config.token, 'session_id': self.session_id, - 'seq': self.seq + 'seq': self.seq, }) else: self.log.info('WS Opened: sending identify payload') @@ -205,7 +205,7 @@ class GatewayClient(LoggingClass): '$browser': 'disco', '$device': 'disco', '$referrer': '', - } + }, }) def on_close(self, code, reason): diff --git a/disco/gateway/events.py b/disco/gateway/events.py index 8d5e882..9b76525 100644 --- a/disco/gateway/events.py +++ b/disco/gateway/events.py @@ -630,7 +630,7 @@ class MessageReactionAdd(GatewayEvent): self.channel_id, self.message_id, self.emoji.to_string() if self.emoji.id else self.emoji.name, - self.user_id + self.user_id, ) @property diff --git a/disco/gateway/ipc.py b/disco/gateway/ipc.py index bcd3383..c92ecf2 100644 --- a/disco/gateway/ipc.py +++ b/disco/gateway/ipc.py @@ -68,7 +68,7 @@ class GIPCProxy(LoggingClass): try: self.handle(mtype, data) - except: + except Exception: self.log.exception('Error in GIPCProxy:') def execute(self, func): diff --git a/disco/gateway/sharder.py b/disco/gateway/sharder.py index 8fc9d0a..84cea49 100644 --- a/disco/gateway/sharder.py +++ b/disco/gateway/sharder.py @@ -21,7 +21,7 @@ from disco.util.serializer import dump_function, load_function def run_shard(config, shard_id, pipe): setup_logging( level=logging.INFO, - format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(shard_id) + format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(shard_id), ) config.shard_id = shard_id @@ -41,17 +41,23 @@ class ShardHelper(object): for sid in range(self.count): yield sid - def on(self, id, func): - if id == self.bot.client.config.shard_id: + def on(self, sid, func): + if sid == self.bot.client.config.shard_id: result = gevent.event.AsyncResult() result.set(func(self.bot)) return result - return self.bot.sharder.call(('run_on', ), id, dump_function(func)) + return self.bot.sharder.call(('run_on', ), sid, dump_function(func)) def all(self, func, timeout=None): pool = gevent.pool.Pool(self.count) - return dict(zip(range(self.count), pool.imap(lambda i: self.on(i, func).wait(timeout=timeout), range(self.count)))) + return dict(zip( + range(self.count), + pool.imap( + lambda i: self.on(i, func).wait(timeout=timeout), + range(self.count), + ), + )) def for_id(self, sid, func): shard = calculate_shard(self.count, sid) @@ -79,7 +85,7 @@ class AutoSharder(object): logging.basicConfig( level=logging.INFO, - format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(id) + format='{} [%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s'.format(id), ) @staticmethod diff --git a/disco/state.py b/disco/state.py index 26c9eba..a25dc27 100644 --- a/disco/state.py +++ b/disco/state.py @@ -90,7 +90,7 @@ class State(object): 'Ready', 'GuildCreate', 'GuildUpdate', 'GuildDelete', 'GuildMemberAdd', 'GuildMemberRemove', 'GuildMemberUpdate', 'GuildMembersChunk', 'GuildRoleCreate', 'GuildRoleUpdate', 'GuildRoleDelete', 'GuildEmojisUpdate', 'ChannelCreate', 'ChannelUpdate', 'ChannelDelete', 'VoiceStateUpdate', 'MessageCreate', - 'PresenceUpdate' + 'PresenceUpdate', ] def __init__(self, client, config): @@ -202,7 +202,7 @@ class State(object): 'channels', 'members', 'voice_states', - 'presences' + 'presences', ]) def on_guild_delete(self, event): diff --git a/disco/types/__init__.py b/disco/types/__init__.py index 5824ec5..dffaccc 100644 --- a/disco/types/__init__.py +++ b/disco/types/__init__.py @@ -1,6 +1,18 @@ -from disco.types.base import UNSET -from disco.types.channel import Channel -from disco.types.guild import Guild, GuildMember, Role -from disco.types.user import User -from disco.types.message import Message -from disco.types.voice import VoiceState +from disco.types.base import UNSET # noqa: F401 +from disco.types.channel import Channel # noqa: F401 +from disco.types.guild import Guild, GuildMember, Role # noqa: F401 +from disco.types.user import User # noqa: F401 +from disco.types.message import Message # noqa: F401 +from disco.types.voice import VoiceState # noqa: F401 + +# TODO: deprecate this entire file +__all__ = { + 'UNSET', + 'Channel', + 'Guild', + 'GuildMember', + 'Role', + 'User', + 'Message', + 'VoiceState', +} diff --git a/disco/types/base.py b/disco/types/base.py index 3dfea3d..bacfe26 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -11,7 +11,7 @@ from disco.util.hashmap import HashMap DATETIME_FORMATS = [ '%Y-%m-%dT%H:%M:%S.%f', - '%Y-%m-%dT%H:%M:%S' + '%Y-%m-%dT%H:%M:%S', ] @@ -373,7 +373,7 @@ class Model(six.with_metaclass(ModelMeta, Chainable)): if isinstance(getattr(type(self), name), property): try: delattr(self, name) - except: + except Exception: pass def to_dict(self, ignore=None): @@ -411,7 +411,7 @@ class Model(six.with_metaclass(ModelMeta, Chainable)): for k, v in six.iteritems(data): try: setattr(item, k, v) - except: + except Exception: pass diff --git a/disco/types/channel.py b/disco/types/channel.py index f8fbc6d..89f6716 100644 --- a/disco/types/channel.py +++ b/disco/types/channel.py @@ -24,7 +24,7 @@ ChannelType = Enum( PermissionOverwriteType = Enum( ROLE='role', - MEMBER='member' + MEMBER='member', ) @@ -69,7 +69,7 @@ class PermissionOverwrite(ChannelSubType): type=ptype, allow=allow, deny=deny, - channel_id=channel.id + channel_id=channel.id, ).save() @property @@ -139,7 +139,7 @@ class Channel(SlottedModel, Permissible): self.attach(six.itervalues(self.overwrites), {'channel_id': self.id, 'channel': self}) def __str__(self): - return u'#{}'.format(self.name) if self.name else unicode(self.id) + return u'#{}'.format(self.name) if self.name else six.text_type(self.id) def __repr__(self): return u''.format(self.id, self) diff --git a/disco/types/guild.py b/disco/types/guild.py index 884bd9a..5c2a0d7 100644 --- a/disco/types/guild.py +++ b/disco/types/guild.py @@ -9,7 +9,7 @@ from disco.util.paginator import Paginator from disco.util.snowflake import to_snowflake from disco.types.base import ( SlottedModel, Field, ListField, AutoDictField, DictField, snowflake, text, enum, datetime, - cached_property + cached_property, ) from disco.types.user import User from disco.types.voice import VoiceState @@ -29,7 +29,7 @@ VerificationLevel = Enum( ExplicitContentFilterLevel = Enum( NONE=0, WITHOUT_ROLES=1, - ALL=2 + ALL=2, ) DefaultMessageNotificationsLevel = Enum( @@ -449,9 +449,9 @@ class Guild(SlottedModel, Permissible): return self.client.api.guilds_channels_create(self.id, *args, **kwargs) def create_category(self, name, permission_overwrites=[], position=None, reason=None): - ''' + """ Creates a category within the guild. - ''' + """ return self.client.api.guilds_channels_create( self.id, ChannelType.GUILD_CATEGORY, name=name, permission_overwrites=permission_overwrites, position=position, reason=reason, @@ -465,9 +465,9 @@ class Guild(SlottedModel, Permissible): nsfw=None, position=None, reason=None): - ''' + """ Creates a text channel within the guild. - ''' + """ return self.client.api.guilds_channels_create( self.id, ChannelType.GUILD_TEXT, name=name, permission_overwrites=permission_overwrites, parent_id=parent_id, nsfw=nsfw, position=position, reason=reason, @@ -482,9 +482,9 @@ class Guild(SlottedModel, Permissible): user_limit=None, position=None, reason=None): - ''' + """ Creates a voice channel within the guild. - ''' + """ return self.client.api.guilds_channels_create( self.id, ChannelType.GUILD_VOICE, name=name, permission_overwrites=permission_overwrites, parent_id=parent_id, bitrate=bitrate, user_limit=user_limit, position=position, reason=None) diff --git a/disco/types/message.py b/disco/types/message.py index 80ae419..dcac07e 100644 --- a/disco/types/message.py +++ b/disco/types/message.py @@ -8,7 +8,7 @@ from holster.enum import Enum from disco.types.base import ( SlottedModel, Field, ListField, AutoDictField, snowflake, text, - datetime, enum, cached_property + datetime, enum, cached_property, ) from disco.util.paginator import Paginator from disco.util.snowflake import to_snowflake diff --git a/disco/types/user.py b/disco/types/user.py index d6e5938..b35dc47 100644 --- a/disco/types/user.py +++ b/disco/types/user.py @@ -30,7 +30,7 @@ class User(SlottedModel, with_equality('id'), with_hash('id')): self.id, self.avatar, fmt, - size + size, ) @property @@ -65,7 +65,7 @@ Status = Enum( 'IDLE', 'DND', 'INVISIBLE', - 'OFFLINE' + 'OFFLINE', ) diff --git a/disco/types/webhook.py b/disco/types/webhook.py index fa73aac..ee8c0b9 100644 --- a/disco/types/webhook.py +++ b/disco/types/webhook.py @@ -49,7 +49,16 @@ class Webhook(SlottedModel): else: return self.client.api.webhooks_modify(self.id, name, avatar) - def execute(self, content=None, username=None, avatar_url=None, tts=False, fobj=None, embeds=[], wait=False, client=None): + def execute( + self, + content=None, + username=None, + avatar_url=None, + tts=False, + fobj=None, + embeds=[], + wait=False, + client=None): # TODO: support file stuff properly client = client or self.client.api diff --git a/disco/util/hashmap.py b/disco/util/hashmap.py index 74541b6..b689032 100644 --- a/disco/util/hashmap.py +++ b/disco/util/hashmap.py @@ -29,7 +29,7 @@ class HashMap(dict): def select(self, *args, **kwargs): if kwargs: - args += tuple([kwargs]) + args += tuple(kwargs) for obj in self.values(): for check in args: diff --git a/disco/util/limiter.py b/disco/util/limiter.py index 493d4ae..8997790 100644 --- a/disco/util/limiter.py +++ b/disco/util/limiter.py @@ -1,4 +1,3 @@ -import time import gevent diff --git a/disco/util/logging.py b/disco/util/logging.py index 61a7b42..c4587d2 100644 --- a/disco/util/logging.py +++ b/disco/util/logging.py @@ -5,7 +5,7 @@ import logging LEVEL_OVERRIDES = { - 'requests': logging.WARNING + 'requests': logging.WARNING, } LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s:%(lineno)d - %(message)s' diff --git a/disco/voice/__init__.py b/disco/voice/__init__.py index b4a7f6c..437f477 100644 --- a/disco/voice/__init__.py +++ b/disco/voice/__init__.py @@ -1,3 +1,5 @@ -from disco.voice.client import * -from disco.voice.player import * -from disco.voice.playable import * +from disco.voice.client import * # noqa: F401,F403 +from disco.voice.player import * # noqa: F401,F403 +from disco.voice.playable import * # noqa: F401,F403 + +# TODO: deprecate this file diff --git a/disco/voice/client.py b/disco/voice/client.py index 35b68f8..cbb75c6 100644 --- a/disco/voice/client.py +++ b/disco/voice/client.py @@ -205,8 +205,8 @@ class VoiceClient(LoggingClass): 'data': { 'port': port, 'address': ip, - 'mode': 'xsalsa20_poly1305' - } + 'mode': 'xsalsa20_poly1305', + }, }) def on_voice_sdp(self, sdp): @@ -245,7 +245,7 @@ class VoiceClient(LoggingClass): try: data = self.encoder.decode(msg) self.packets.emit(VoiceOPCode[data['op']], data['d']) - except: + except Exception: self.log.exception('Failed to parse voice gateway message: ') def on_error(self, err): @@ -256,7 +256,7 @@ class VoiceClient(LoggingClass): 'server_id': self.channel.guild_id, 'user_id': self.client.state.me.id, 'session_id': self.client.gw.session_id, - 'token': self.token + 'token': self.token, }) def on_close(self, code, error): diff --git a/disco/voice/opus.py b/disco/voice/opus.py index a86a4ed..1e68093 100644 --- a/disco/voice/opus.py +++ b/disco/voice/opus.py @@ -62,7 +62,7 @@ class BaseOpus(LoggingClass): Application = Enum( AUDIO=2049, VOIP=2048, - LOWDELAY=2051 + LOWDELAY=2051, ) diff --git a/disco/voice/playable.py b/disco/voice/playable.py index 12ed9ef..55e37f2 100644 --- a/disco/voice/playable.py +++ b/disco/voice/playable.py @@ -13,7 +13,7 @@ from disco.voice.opus import OpusEncoder try: from cStringIO import cStringIO as BufferedIO -except: +except ImportError: if six.PY2: from StringIO import StringIO as BufferedIO else: @@ -139,7 +139,7 @@ class FFmpegInput(BaseInput, AbstractOpus): '-ar', str(self.sampling_rate), '-ac', str(self.channels), '-loglevel', 'warning', - 'pipe:1' + 'pipe:1', ] self._proc = subprocess.Popen(args, stdin=None, stdout=subprocess.PIPE) return self._proc diff --git a/disco/voice/player.py b/disco/voice/player.py index 7fa6ee0..a38dff9 100644 --- a/disco/voice/player.py +++ b/disco/voice/player.py @@ -16,7 +16,7 @@ class Player(object): 'STOP_PLAY', 'PAUSE_PLAY', 'RESUME_PLAY', - 'DISCONNECT' + 'DISCONNECT', ) def __init__(self, client, queue=None): diff --git a/tests/types/embeds.py b/tests/types/embeds.py index ef60361..a0afa7f 100644 --- a/tests/types/embeds.py +++ b/tests/types/embeds.py @@ -1,6 +1,5 @@ from unittest import TestCase -from datetime import datetime from disco.types.message import MessageEmbed @@ -29,4 +28,3 @@ class TestEmbeds(TestCase): self.assertEqual(obj['title'], 'Test Title') self.assertEqual(obj['description'], 'Test Description') self.assertEqual(obj['url'], 'https://test.url/') -