mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
[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:
|
||||
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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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`.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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'
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user