[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.
This commit is contained in:
parent
4ae8e81660
commit
fa46b07db1
@ -45,8 +45,8 @@ class Bot(commands.{base}):
|
|||||||
for cog in config.cogs:
|
for cog in config.cogs:
|
||||||
try:
|
try:
|
||||||
self.load_extension(cog)
|
self.load_extension(cog)
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
print('Could not load extension {{0}} due to {{1.__class__.__name__}}: {{1}}'.format(cog, e))
|
print('Could not load extension {{0}} due to {{1.__class__.__name__}}: {{1}}'.format(cog, exc))
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print('Logged on as {{0}} (ID: {{0.id}})'.format(self.user))
|
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
|
# since we already checked above that we're >3.5
|
||||||
try:
|
try:
|
||||||
new_directory.mkdir(exist_ok=True, parents=True)
|
new_directory.mkdir(exist_ok=True, parents=True)
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
parser.error('could not create our bot directory ({})'.format(e))
|
parser.error('could not create our bot directory ({})'.format(exc))
|
||||||
|
|
||||||
cogs = new_directory / 'cogs'
|
cogs = new_directory / 'cogs'
|
||||||
|
|
||||||
@ -190,28 +190,28 @@ def newbot(parser, args):
|
|||||||
cogs.mkdir(exist_ok=True)
|
cogs.mkdir(exist_ok=True)
|
||||||
init = cogs / '__init__.py'
|
init = cogs / '__init__.py'
|
||||||
init.touch()
|
init.touch()
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
print('warning: could not create cogs directory ({})'.format(e))
|
print('warning: could not create cogs directory ({})'.format(exc))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(str(new_directory / 'config.py'), 'w', encoding='utf-8') as fp:
|
with open(str(new_directory / 'config.py'), 'w', encoding='utf-8') as fp:
|
||||||
fp.write('token = "place your token here"\ncogs = []\n')
|
fp.write('token = "place your token here"\ncogs = []\n')
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
parser.error('could not create config file ({})'.format(e))
|
parser.error('could not create config file ({})'.format(exc))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
|
with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
|
||||||
base = 'Bot' if not args.sharded else 'AutoShardedBot'
|
base = 'Bot' if not args.sharded else 'AutoShardedBot'
|
||||||
fp.write(bot_template.format(base=base, prefix=args.prefix))
|
fp.write(bot_template.format(base=base, prefix=args.prefix))
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
parser.error('could not create bot file ({})'.format(e))
|
parser.error('could not create bot file ({})'.format(exc))
|
||||||
|
|
||||||
if not args.no_git:
|
if not args.no_git:
|
||||||
try:
|
try:
|
||||||
with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
|
with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
|
||||||
fp.write(gitignore_template)
|
fp.write(gitignore_template)
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
print('warning: could not create .gitignore file ({})'.format(e))
|
print('warning: could not create .gitignore file ({})'.format(exc))
|
||||||
|
|
||||||
print('successfully made bot at', new_directory)
|
print('successfully made bot at', new_directory)
|
||||||
|
|
||||||
@ -222,8 +222,8 @@ def newcog(parser, args):
|
|||||||
cog_dir = to_path(parser, args.directory)
|
cog_dir = to_path(parser, args.directory)
|
||||||
try:
|
try:
|
||||||
cog_dir.mkdir(exist_ok=True)
|
cog_dir.mkdir(exist_ok=True)
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
print('warning: could not create cogs directory ({})'.format(e))
|
print('warning: could not create cogs directory ({})'.format(exc))
|
||||||
|
|
||||||
directory = cog_dir / to_path(parser, args.name)
|
directory = cog_dir / to_path(parser, args.name)
|
||||||
directory = directory.with_suffix('.py')
|
directory = directory.with_suffix('.py')
|
||||||
@ -239,8 +239,8 @@ def newcog(parser, args):
|
|||||||
else:
|
else:
|
||||||
name = name.title()
|
name = name.title()
|
||||||
fp.write(cog_template.format(name=name, extra=extra))
|
fp.write(cog_template.format(name=name, extra=extra))
|
||||||
except OSError as e:
|
except OSError as exc:
|
||||||
parser.error('could not create cog file ({})'.format(e))
|
parser.error('could not create cog file ({})'.format(exc))
|
||||||
else:
|
else:
|
||||||
print('successfully made cog at', directory)
|
print('successfully made cog at', directory)
|
||||||
|
|
||||||
|
@ -246,8 +246,8 @@ class Client:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
result = condition(*args)
|
result = condition(*args)
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
future.set_exception(e)
|
future.set_exception(exc)
|
||||||
removed.append(i)
|
removed.append(i)
|
||||||
else:
|
else:
|
||||||
if result:
|
if result:
|
||||||
@ -406,11 +406,11 @@ class Client:
|
|||||||
aiohttp.ClientError,
|
aiohttp.ClientError,
|
||||||
asyncio.TimeoutError,
|
asyncio.TimeoutError,
|
||||||
websockets.InvalidHandshake,
|
websockets.InvalidHandshake,
|
||||||
websockets.WebSocketProtocolError) as e:
|
websockets.WebSocketProtocolError) as exc:
|
||||||
|
|
||||||
if not reconnect:
|
if not reconnect:
|
||||||
await self.close()
|
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
|
# clean close, don't re-raise this
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
@ -422,8 +422,8 @@ class Client:
|
|||||||
# such as a clean disconnect (1000) or a bad state (bad token, no sharding, etc)
|
# 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
|
# sometimes, discord sends us 1000 for unknown reasons so we should reconnect
|
||||||
# regardless and rely on is_closed instead
|
# regardless and rely on is_closed instead
|
||||||
if isinstance(e, ConnectionClosed):
|
if isinstance(exc, ConnectionClosed):
|
||||||
if e.code != 1000:
|
if exc.code != 1000:
|
||||||
await self.close()
|
await self.close()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -897,8 +897,8 @@ class BotBase(GroupMixin):
|
|||||||
try:
|
try:
|
||||||
if (await self.can_run(ctx, call_once=True)):
|
if (await self.can_run(ctx, call_once=True)):
|
||||||
await ctx.command.invoke(ctx)
|
await ctx.command.invoke(ctx)
|
||||||
except CommandError as e:
|
except CommandError as exc:
|
||||||
await ctx.command.dispatch_error(ctx, e)
|
await ctx.command.dispatch_error(ctx, exc)
|
||||||
else:
|
else:
|
||||||
self.dispatch('command_completion', ctx)
|
self.dispatch('command_completion', ctx)
|
||||||
elif ctx.invoked_with:
|
elif ctx.invoked_with:
|
||||||
|
@ -343,8 +343,8 @@ class InviteConverter(Converter):
|
|||||||
try:
|
try:
|
||||||
invite = await ctx.bot.get_invite(argument)
|
invite = await ctx.bot.get_invite(argument)
|
||||||
return invite
|
return invite
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
raise BadArgument('Invite is invalid or expired') from e
|
raise BadArgument('Invite is invalid or expired') from exc
|
||||||
|
|
||||||
class EmojiConverter(IDConverter):
|
class EmojiConverter(IDConverter):
|
||||||
"""Converts to a :class:`Emoji`.
|
"""Converts to a :class:`Emoji`.
|
||||||
|
@ -49,8 +49,8 @@ def wrap_callback(coro):
|
|||||||
raise
|
raise
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
raise CommandInvokeError(e) from e
|
raise CommandInvokeError(exc) from exc
|
||||||
return ret
|
return ret
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ def hooked_wrapped_callback(command, ctx, coro):
|
|||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
ctx.command_failed = True
|
ctx.command_failed = True
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
ctx.command_failed = True
|
ctx.command_failed = True
|
||||||
raise CommandInvokeError(e) from e
|
raise CommandInvokeError(exc) from exc
|
||||||
finally:
|
finally:
|
||||||
await command.call_after_hooks(ctx)
|
await command.call_after_hooks(ctx)
|
||||||
return ret
|
return ret
|
||||||
@ -262,20 +262,20 @@ class Command:
|
|||||||
return ret
|
return ret
|
||||||
except CommandError:
|
except CommandError:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
raise ConversionError(converter, e) from e
|
raise ConversionError(converter, exc) from exc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return converter(argument)
|
return converter(argument)
|
||||||
except CommandError:
|
except CommandError:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
try:
|
try:
|
||||||
name = converter.__name__
|
name = converter.__name__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = converter.__class__.__name__
|
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):
|
async def do_conversion(self, ctx, converter, argument, param):
|
||||||
try:
|
try:
|
||||||
@ -296,8 +296,8 @@ class Command:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
value = await self._actual_conversion(ctx, conv, argument, param)
|
value = await self._actual_conversion(ctx, conv, argument, param)
|
||||||
except CommandError as e:
|
except CommandError as exc:
|
||||||
errors.append(e)
|
errors.append(exc)
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -413,8 +413,8 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
valid = entry.predicate(data)
|
valid = entry.predicate(data)
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
future.set_exception(e)
|
future.set_exception(exc)
|
||||||
removed.append(index)
|
removed.append(index)
|
||||||
else:
|
else:
|
||||||
if valid:
|
if valid:
|
||||||
@ -445,13 +445,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
try:
|
try:
|
||||||
msg = await self.recv()
|
msg = await self.recv()
|
||||||
await self.received_message(msg)
|
await self.received_message(msg)
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as exc:
|
||||||
if self._can_handle_close(e.code):
|
if self._can_handle_close(exc.code):
|
||||||
log.info('Websocket closed with %s (%s), attempting a reconnect.', e.code, e.reason)
|
log.info('Websocket closed with %s (%s), attempting a reconnect.', exc.code, exc.reason)
|
||||||
raise ResumeWebSocket(self.shard_id) from e
|
raise ResumeWebSocket(self.shard_id) from exc
|
||||||
else:
|
else:
|
||||||
log.info('Websocket closed with %s (%s), cannot reconnect.', e.code, e.reason)
|
log.info('Websocket closed with %s (%s), cannot reconnect.', exc.code, exc.reason)
|
||||||
raise ConnectionClosed(e, shard_id=self.shard_id) from e
|
raise ConnectionClosed(exc, shard_id=self.shard_id) from exc
|
||||||
|
|
||||||
async def send(self, data):
|
async def send(self, data):
|
||||||
self._dispatch('socket_raw_send', data)
|
self._dispatch('socket_raw_send', data)
|
||||||
@ -459,10 +459,10 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
|
|
||||||
async def send_as_json(self, data):
|
async def send_as_json(self, data):
|
||||||
try:
|
try:
|
||||||
await self.send(utils.to_json(data))
|
await super().send(utils.to_json(data))
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as exc:
|
||||||
if not self._can_handle_close(e.code):
|
if not self._can_handle_close(exc.code):
|
||||||
raise ConnectionClosed(e, shard_id=self.shard_id) from e
|
raise ConnectionClosed(exc, shard_id=self.shard_id) from exc
|
||||||
|
|
||||||
async def change_presence(self, *, activity=None, status=None, afk=False, since=0.0):
|
async def change_presence(self, *, activity=None, status=None, afk=False, since=0.0):
|
||||||
if activity is not None:
|
if activity is not None:
|
||||||
@ -679,8 +679,8 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
try:
|
try:
|
||||||
msg = await asyncio.wait_for(self.recv(), timeout=30.0, loop=self.loop)
|
msg = await asyncio.wait_for(self.recv(), timeout=30.0, loop=self.loop)
|
||||||
await self.received_message(json.loads(msg))
|
await self.received_message(json.loads(msg))
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as exc:
|
||||||
raise ConnectionClosed(e, shard_id=None) from e
|
raise ConnectionClosed(exc, shard_id=None) from exc
|
||||||
|
|
||||||
async def close_connection(self, *args, **kwargs):
|
async def close_connection(self, *args, **kwargs):
|
||||||
if self._keep_alive:
|
if self._keep_alive:
|
||||||
|
@ -244,10 +244,10 @@ class HTTPClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = await self.request(Route('GET', '/users/@me'))
|
data = await self.request(Route('GET', '/users/@me'))
|
||||||
except HTTPException as e:
|
except HTTPException as exc:
|
||||||
self._token(old_token, bot=old_bot)
|
self._token(old_token, bot=old_bot)
|
||||||
if e.response.status == 401:
|
if exc.response.status == 401:
|
||||||
raise LoginFailure('Improper token has been passed.') from e
|
raise LoginFailure('Improper token has been passed.') from exc
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -742,8 +742,8 @@ class HTTPClient:
|
|||||||
async def get_gateway(self, *, encoding='json', v=6, zlib=True):
|
async def get_gateway(self, *, encoding='json', v=6, zlib=True):
|
||||||
try:
|
try:
|
||||||
data = await self.request(Route('GET', '/gateway'))
|
data = await self.request(Route('GET', '/gateway'))
|
||||||
except HTTPException as e:
|
except HTTPException as exc:
|
||||||
raise GatewayNotFound() from e
|
raise GatewayNotFound() from exc
|
||||||
if zlib:
|
if zlib:
|
||||||
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
|
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
|
||||||
else:
|
else:
|
||||||
@ -753,8 +753,8 @@ class HTTPClient:
|
|||||||
async def get_bot_gateway(self, *, encoding='json', v=6, zlib=True):
|
async def get_bot_gateway(self, *, encoding='json', v=6, zlib=True):
|
||||||
try:
|
try:
|
||||||
data = await self.request(Route('GET', '/gateway/bot'))
|
data = await self.request(Route('GET', '/gateway/bot'))
|
||||||
except HTTPException as e:
|
except HTTPException as exc:
|
||||||
raise GatewayNotFound() from e
|
raise GatewayNotFound() from exc
|
||||||
|
|
||||||
if zlib:
|
if zlib:
|
||||||
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
|
value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
|
||||||
|
@ -162,8 +162,8 @@ class FFmpegPCMAudio(AudioSource):
|
|||||||
self._stdout = self._process.stdout
|
self._stdout = self._process.stdout
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise ClientException(executable + ' was not found.') from None
|
raise ClientException(executable + ' was not found.') from None
|
||||||
except subprocess.SubprocessError as e:
|
except subprocess.SubprocessError as exc:
|
||||||
raise ClientException('Popen failed: {0.__class__.__name__}: {0}'.format(e)) from e
|
raise ClientException('Popen failed: {0.__class__.__name__}: {0}'.format(exc)) from exc
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
ret = self._stdout.read(OpusEncoder.FRAME_SIZE)
|
ret = self._stdout.read(OpusEncoder.FRAME_SIZE)
|
||||||
@ -292,8 +292,8 @@ class AudioPlayer(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self._do_run()
|
self._do_run()
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
self._current_error = e
|
self._current_error = exc
|
||||||
self.stop()
|
self.stop()
|
||||||
finally:
|
finally:
|
||||||
self.source.cleanup()
|
self.source.cleanup()
|
||||||
|
@ -115,8 +115,8 @@ class ConnectionState:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
passed = listener.predicate(argument)
|
passed = listener.predicate(argument)
|
||||||
except Exception as e:
|
except Exception as exc:
|
||||||
future.set_exception(e)
|
future.set_exception(exc)
|
||||||
removed.append(i)
|
removed.append(i)
|
||||||
else:
|
else:
|
||||||
if passed:
|
if passed:
|
||||||
|
@ -224,9 +224,9 @@ class VoiceClient:
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
await self.ws.poll_event()
|
await self.ws.poll_event()
|
||||||
except (ConnectionClosed, asyncio.TimeoutError) as e:
|
except (ConnectionClosed, asyncio.TimeoutError) as exc:
|
||||||
if isinstance(e, ConnectionClosed):
|
if isinstance(exc, ConnectionClosed):
|
||||||
if e.code == 1000:
|
if exc.code == 1000:
|
||||||
await self.disconnect()
|
await self.disconnect()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user