aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHornwitser <[email protected]>2018-08-01 11:41:15 +0200
committerRapptz <[email protected]>2018-11-24 22:17:57 -0500
commitfa46b07db15f5ce41be3f4944d2ff011794207d5 (patch)
tree0a87a0731c797cfadb69f7812ee4813628b4eba2
parent[lint] Remove redundant exception variables (diff)
downloaddiscord.py-fa46b07db15f5ce41be3f4944d2ff011794207d5.tar.xz
discord.py-fa46b07db15f5ce41be3f4944d2ff011794207d5.zip
[lint] Rename exception variables to exc
Use the more explicit (and common) exc instead of e as the variable holding the exception in except handlers.
-rw-r--r--discord/__main__.py32
-rw-r--r--discord/client.py12
-rw-r--r--discord/ext/commands/bot.py4
-rw-r--r--discord/ext/commands/converter.py4
-rw-r--r--discord/ext/commands/core.py20
-rw-r--r--discord/gateway.py28
-rw-r--r--discord/http.py14
-rw-r--r--discord/player.py8
-rw-r--r--discord/state.py4
-rw-r--r--discord/voice_client.py6
10 files changed, 66 insertions, 66 deletions
diff --git a/discord/__main__.py b/discord/__main__.py
index 88837c79..983f388e 100644
--- a/discord/__main__.py
+++ b/discord/__main__.py
@@ -45,8 +45,8 @@ class Bot(commands.{base}):
for cog in config.cogs:
try:
self.load_extension(cog)
- except Exception as e:
- print('Could not load extension {{0}} due to {{1.__class__.__name__}}: {{1}}'.format(cog, e))
+ except Exception as exc:
+ print('Could not load extension {{0}} due to {{1.__class__.__name__}}: {{1}}'.format(cog, exc))
async def on_ready(self):
print('Logged on as {{0}} (ID: {{0.id}})'.format(self.user))
@@ -181,8 +181,8 @@ def newbot(parser, args):
# since we already checked above that we're >3.5
try:
new_directory.mkdir(exist_ok=True, parents=True)
- except OSError as e:
- parser.error('could not create our bot directory ({})'.format(e))
+ except OSError as exc:
+ parser.error('could not create our bot directory ({})'.format(exc))
cogs = new_directory / 'cogs'
@@ -190,28 +190,28 @@ def newbot(parser, args):
cogs.mkdir(exist_ok=True)
init = cogs / '__init__.py'
init.touch()
- except OSError as e:
- print('warning: could not create cogs directory ({})'.format(e))
+ except OSError as exc:
+ print('warning: could not create cogs directory ({})'.format(exc))
try:
with open(str(new_directory / 'config.py'), 'w', encoding='utf-8') as fp:
fp.write('token = "place your token here"\ncogs = []\n')
- except OSError as e:
- parser.error('could not create config file ({})'.format(e))
+ except OSError as exc:
+ parser.error('could not create config file ({})'.format(exc))
try:
with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
base = 'Bot' if not args.sharded else 'AutoShardedBot'
fp.write(bot_template.format(base=base, prefix=args.prefix))
- except OSError as e:
- parser.error('could not create bot file ({})'.format(e))
+ except OSError as exc:
+ parser.error('could not create bot file ({})'.format(exc))
if not args.no_git:
try:
with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
fp.write(gitignore_template)
- except OSError as e:
- print('warning: could not create .gitignore file ({})'.format(e))
+ except OSError as exc:
+ print('warning: could not create .gitignore file ({})'.format(exc))
print('successfully made bot at', new_directory)
@@ -222,8 +222,8 @@ def newcog(parser, args):
cog_dir = to_path(parser, args.directory)
try:
cog_dir.mkdir(exist_ok=True)
- except OSError as e:
- print('warning: could not create cogs directory ({})'.format(e))
+ except OSError as exc:
+ print('warning: could not create cogs directory ({})'.format(exc))
directory = cog_dir / to_path(parser, args.name)
directory = directory.with_suffix('.py')
@@ -239,8 +239,8 @@ def newcog(parser, args):
else:
name = name.title()
fp.write(cog_template.format(name=name, extra=extra))
- except OSError as e:
- parser.error('could not create cog file ({})'.format(e))
+ except OSError as exc:
+ parser.error('could not create cog file ({})'.format(exc))
else:
print('successfully made cog at', directory)
diff --git a/discord/client.py b/discord/client.py
index 6251e65e..e5269828 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -246,8 +246,8 @@ class Client:
try:
result = condition(*args)
- except Exception as e:
- future.set_exception(e)
+ except Exception as exc:
+ future.set_exception(exc)
removed.append(i)
else:
if result:
@@ -406,11 +406,11 @@ class Client:
aiohttp.ClientError,
asyncio.TimeoutError,
websockets.InvalidHandshake,
- websockets.WebSocketProtocolError) as e:
+ websockets.WebSocketProtocolError) as exc:
if not reconnect:
await self.close()
- if isinstance(e, ConnectionClosed) and e.code == 1000:
+ if isinstance(exc, ConnectionClosed) and exc.code == 1000:
# clean close, don't re-raise this
return
raise
@@ -422,8 +422,8 @@ class Client:
# such as a clean disconnect (1000) or a bad state (bad token, no sharding, etc)
# sometimes, discord sends us 1000 for unknown reasons so we should reconnect
# regardless and rely on is_closed instead
- if isinstance(e, ConnectionClosed):
- if e.code != 1000:
+ if isinstance(exc, ConnectionClosed):
+ if exc.code != 1000:
await self.close()
raise
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index 04a5452f..b934be9b 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -897,8 +897,8 @@ class BotBase(GroupMixin):
try:
if (await self.can_run(ctx, call_once=True)):
await ctx.command.invoke(ctx)
- except CommandError as e:
- await ctx.command.dispatch_error(ctx, e)
+ except CommandError as exc:
+ await ctx.command.dispatch_error(ctx, exc)
else:
self.dispatch('command_completion', ctx)
elif ctx.invoked_with:
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py
index a66a61f3..de189e6c 100644
--- a/discord/ext/commands/converter.py
+++ b/discord/ext/commands/converter.py
@@ -343,8 +343,8 @@ class InviteConverter(Converter):
try:
invite = await ctx.bot.get_invite(argument)
return invite
- except Exception as e:
- raise BadArgument('Invite is invalid or expired') from e
+ except Exception as exc:
+ raise BadArgument('Invite is invalid or expired') from exc
class EmojiConverter(IDConverter):
"""Converts to a :class:`Emoji`.
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 8e28159d..e2e68192 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -49,8 +49,8 @@ def wrap_callback(coro):
raise
except asyncio.CancelledError:
return
- except Exception as e:
- raise CommandInvokeError(e) from e
+ except Exception as exc:
+ raise CommandInvokeError(exc) from exc
return ret
return wrapped
@@ -65,9 +65,9 @@ def hooked_wrapped_callback(command, ctx, coro):
except asyncio.CancelledError:
ctx.command_failed = True
return
- except Exception as e:
+ except Exception as exc:
ctx.command_failed = True
- raise CommandInvokeError(e) from e
+ raise CommandInvokeError(exc) from exc
finally:
await command.call_after_hooks(ctx)
return ret
@@ -262,20 +262,20 @@ class Command:
return ret
except CommandError:
raise
- except Exception as e:
- raise ConversionError(converter, e) from e
+ except Exception as exc:
+ raise ConversionError(converter, exc) from exc
try:
return converter(argument)
except CommandError:
raise
- except Exception as e:
+ except Exception as exc:
try:
name = converter.__name__
except AttributeError:
name = converter.__class__.__name__
- raise BadArgument('Converting to "{}" failed for parameter "{}".'.format(name, param.name)) from e
+ raise BadArgument('Converting to "{}" failed for parameter "{}".'.format(name, param.name)) from exc
async def do_conversion(self, ctx, converter, argument, param):
try:
@@ -296,8 +296,8 @@ class Command:
try:
value = await self._actual_conversion(ctx, conv, argument, param)
- except CommandError as e:
- errors.append(e)
+ except CommandError as exc:
+ errors.append(exc)
else:
return value
diff --git a/discord/gateway.py b/discord/gateway.py
index 7e04018a..b3fca3a3 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -413,8 +413,8 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
try:
valid = entry.predicate(data)
- except Exception as e:
- future.set_exception(e)
+ except Exception as exc:
+ future.set_exception(exc)
removed.append(index)
else:
if valid:
@@ -445,13 +445,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
try:
msg = await self.recv()
await self.received_message(msg)
- except websockets.exceptions.ConnectionClosed as e:
- if self._can_handle_close(e.code):
- log.info('Websocket closed with %s (%s), attempting a reconnect.', e.code, e.reason)
- raise ResumeWebSocket(self.shard_id) from e
+ except websockets.exceptions.ConnectionClosed as exc:
+ if self._can_handle_close(exc.code):
+ log.info('Websocket closed with %s (%s), attempting a reconnect.', exc.code, exc.reason)
+ raise ResumeWebSocket(self.shard_id) from exc
else:
- log.info('Websocket closed with %s (%s), cannot reconnect.', e.code, e.reason)
- raise ConnectionClosed(e, shard_id=self.shard_id) from e
+ log.info('Websocket closed with %s (%s), cannot reconnect.', exc.code, exc.reason)
+ raise ConnectionClosed(exc, shard_id=self.shard_id) from exc
async def send(self, data):
self._dispatch('socket_raw_send', data)
@@ -459,10 +459,10 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
async def send_as_json(self, data):
try:
- await self.send(utils.to_json(data))
- except websockets.exceptions.ConnectionClosed as e:
- if not self._can_handle_close(e.code):
- raise ConnectionClosed(e, shard_id=self.shard_id) from e
+ await super().send(utils.to_json(data))
+ except websockets.exceptions.ConnectionClosed as exc:
+ if not self._can_handle_close(exc.code):
+ raise ConnectionClosed(exc, shard_id=self.shard_id) from exc
async def change_presence(self, *, activity=None, status=None, afk=False, since=0.0):
if activity is not None:
@@ -679,8 +679,8 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
try:
msg = await asyncio.wait_for(self.recv(), timeout=30.0, loop=self.loop)
await self.received_message(json.loads(msg))
- except websockets.exceptions.ConnectionClosed as e:
- raise ConnectionClosed(e, shard_id=None) from e
+ except websockets.exceptions.ConnectionClosed as exc:
+ raise ConnectionClosed(exc, shard_id=None) from exc
async def close_connection(self, *args, **kwargs):
if self._keep_alive:
diff --git a/discord/http.py b/discord/http.py
index 93e9708d..7fc6abda 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -244,10 +244,10 @@ class HTTPClient:
try:
data = await self.request(Route('GET', '/users/@me'))
- except HTTPException as e:
+ except HTTPException as exc:
self._token(old_token, bot=old_bot)
- if e.response.status == 401:
- raise LoginFailure('Improper token has been passed.') from e
+ if exc.response.status == 401:
+ raise LoginFailure('Improper token has been passed.') from exc
raise
return data
@@ -742,8 +742,8 @@ class HTTPClient:
async def get_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = await self.request(Route('GET', '/gateway'))
- except HTTPException as e:
- raise GatewayNotFound() from e
+ except HTTPException as exc:
+ raise GatewayNotFound() from exc
if zlib:
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
else:
@@ -753,8 +753,8 @@ class HTTPClient:
async def get_bot_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = await self.request(Route('GET', '/gateway/bot'))
- except HTTPException as e:
- raise GatewayNotFound() from e
+ except HTTPException as exc:
+ raise GatewayNotFound() from exc
if zlib:
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
diff --git a/discord/player.py b/discord/player.py
index a31b8fd2..e72d2c43 100644
--- a/discord/player.py
+++ b/discord/player.py
@@ -162,8 +162,8 @@ class FFmpegPCMAudio(AudioSource):
self._stdout = self._process.stdout
except FileNotFoundError:
raise ClientException(executable + ' was not found.') from None
- except subprocess.SubprocessError as e:
- raise ClientException('Popen failed: {0.__class__.__name__}: {0}'.format(e)) from e
+ except subprocess.SubprocessError as exc:
+ raise ClientException('Popen failed: {0.__class__.__name__}: {0}'.format(exc)) from exc
def read(self):
ret = self._stdout.read(OpusEncoder.FRAME_SIZE)
@@ -292,8 +292,8 @@ class AudioPlayer(threading.Thread):
def run(self):
try:
self._do_run()
- except Exception as e:
- self._current_error = e
+ except Exception as exc:
+ self._current_error = exc
self.stop()
finally:
self.source.cleanup()
diff --git a/discord/state.py b/discord/state.py
index 53e453f3..ee542d99 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -115,8 +115,8 @@ class ConnectionState:
try:
passed = listener.predicate(argument)
- except Exception as e:
- future.set_exception(e)
+ except Exception as exc:
+ future.set_exception(exc)
removed.append(i)
else:
if passed:
diff --git a/discord/voice_client.py b/discord/voice_client.py
index 9d189af2..14c54493 100644
--- a/discord/voice_client.py
+++ b/discord/voice_client.py
@@ -224,9 +224,9 @@ class VoiceClient:
while True:
try:
await self.ws.poll_event()
- except (ConnectionClosed, asyncio.TimeoutError) as e:
- if isinstance(e, ConnectionClosed):
- if e.code == 1000:
+ except (ConnectionClosed, asyncio.TimeoutError) as exc:
+ if isinstance(exc, ConnectionClosed):
+ if exc.code == 1000:
await self.disconnect()
break