Browse Source

[lint] Limit unneccessarily broad except clauses

Add exception qualifier(s) to bare except clauses swallowing exceptions.
pull/1739/head
Hornwitser 7 years ago
committed by Rapptz
parent
commit
a71b3b5fa0
  1. 8
      discord/abc.py
  2. 6
      discord/client.py
  3. 2
      discord/context_managers.py
  4. 2
      discord/errors.py
  5. 6
      discord/ext/commands/bot.py
  6. 2
      discord/ext/commands/core.py
  7. 2
      discord/gateway.py
  8. 4
      discord/message.py
  9. 2
      discord/player.py
  10. 2
      discord/shard.py
  11. 2
      discord/voice_client.py

8
discord/abc.py

@ -32,7 +32,7 @@ from collections import namedtuple
from .iterators import HistoryIterator from .iterators import HistoryIterator
from .context_managers import Typing from .context_managers import Typing
from .errors import InvalidArgument, ClientException from .errors import InvalidArgument, ClientException, HTTPException
from .permissions import PermissionOverwrite, Permissions from .permissions import PermissionOverwrite, Permissions
from .role import Role from .role import Role
from .invite import Invite from .invite import Invite
@ -578,7 +578,7 @@ class GuildChannel:
raise InvalidArgument('No overwrite provided.') raise InvalidArgument('No overwrite provided.')
try: try:
overwrite = PermissionOverwrite(**permissions) overwrite = PermissionOverwrite(**permissions)
except: except (ValueError, TypeError):
raise InvalidArgument('Invalid permissions given to keyword arguments.') raise InvalidArgument('Invalid permissions given to keyword arguments.')
else: else:
if len(permissions) > 0: if len(permissions) > 0:
@ -778,7 +778,7 @@ class Messageable(metaclass=abc.ABCMeta):
await asyncio.sleep(delete_after, loop=state.loop) await asyncio.sleep(delete_after, loop=state.loop)
try: try:
await ret.delete() await ret.delete()
except: except HTTPException:
pass pass
asyncio.ensure_future(delete(), loop=state.loop) asyncio.ensure_future(delete(), loop=state.loop)
return ret return ret
@ -981,7 +981,7 @@ class Connectable(metaclass=abc.ABCMeta):
except asyncio.TimeoutError as e: except asyncio.TimeoutError as e:
try: try:
await voice.disconnect(force=True) await voice.disconnect(force=True)
except: except Exception:
# we don't care if disconnect failed because connection failed # we don't care if disconnect failed because connection failed
pass pass
raise e # re-raise raise e # re-raise

6
discord/client.py

@ -444,7 +444,7 @@ class Client:
for voice in self.voice_clients: for voice in self.voice_clients:
try: try:
await voice.disconnect() await voice.disconnect()
except: except Exception:
# if an error happens during disconnects, disregard it. # if an error happens during disconnects, disregard it.
pass pass
@ -489,7 +489,7 @@ class Client:
def _silence_gathered(fut): def _silence_gathered(fut):
try: try:
fut.result() fut.result()
except: except Exception:
pass pass
finally: finally:
loop.stop() loop.stop()
@ -516,7 +516,7 @@ class Client:
try: try:
return task.result() # suppress unused task warning return task.result() # suppress unused task warning
except: except Exception:
return None return None
def run(self, *args, **kwargs): def run(self, *args, **kwargs):

2
discord/context_managers.py

@ -30,7 +30,7 @@ def _typing_done_callback(fut):
# just retrieve any exception and call it a day # just retrieve any exception and call it a day
try: try:
fut.exception() fut.exception()
except: except Exception:
pass pass
class Typing: class Typing:

2
discord/errors.py

@ -58,7 +58,7 @@ def flatten_error_dict(d, key=''):
if isinstance(v, dict): if isinstance(v, dict):
try: try:
_errors = v['_errors'] _errors = v['_errors']
except Exception: except KeyError:
items.extend(flatten_error_dict(v, new_key).items()) items.extend(flatten_error_dict(v, new_key).items())
else: else:
items.append((new_key, ' '.join(x.get('message', '') for x in _errors))) items.append((new_key, ' '.join(x.get('message', '') for x in _errors)))

6
discord/ext/commands/bot.py

@ -195,13 +195,13 @@ class BotBase(GroupMixin):
for extension in tuple(self.extensions): for extension in tuple(self.extensions):
try: try:
self.unload_extension(extension) self.unload_extension(extension)
except: except Exception:
pass pass
for cog in tuple(self.cogs): for cog in tuple(self.cogs):
try: try:
self.remove_cog(cog) self.remove_cog(cog)
except: except Exception:
pass pass
await super().close() await super().close()
@ -759,7 +759,7 @@ class BotBase(GroupMixin):
else: else:
try: try:
func(self) func(self)
except: except Exception:
pass pass
finally: finally:
# finally remove the import.. # finally remove the import..

2
discord/ext/commands/core.py

@ -240,7 +240,7 @@ class Command:
try: try:
module = converter.__module__ module = converter.__module__
except: except AttributeError:
pass pass
else: else:
if module.startswith('discord.') and not module.endswith('converter'): if module.startswith('discord.') and not module.endswith('converter'):

2
discord/gateway.py

@ -76,7 +76,7 @@ class KeepAliveHandler(threading.Thread):
try: try:
f.result() f.result()
except: except Exception:
pass pass
finally: finally:
self.stop() self.stop()

4
discord/message.py

@ -32,7 +32,7 @@ from .reaction import Reaction
from .emoji import Emoji, PartialEmoji from .emoji import Emoji, PartialEmoji
from .calls import CallMessage from .calls import CallMessage
from .enums import MessageType, try_enum from .enums import MessageType, try_enum
from .errors import InvalidArgument, ClientException from .errors import InvalidArgument, ClientException, HTTPException
from .embeds import Embed from .embeds import Embed
class Attachment: class Attachment:
@ -599,7 +599,7 @@ class Message:
await asyncio.sleep(delete_after, loop=self._state.loop) await asyncio.sleep(delete_after, loop=self._state.loop)
try: try:
await self._state.http.delete_message(self.channel.id, self.id) await self._state.http.delete_message(self.channel.id, self.id)
except: except HTTPException:
pass pass
asyncio.ensure_future(delete(), loop=self._state.loop) asyncio.ensure_future(delete(), loop=self._state.loop)

2
discord/player.py

@ -303,7 +303,7 @@ class AudioPlayer(threading.Thread):
if self.after is not None: if self.after is not None:
try: try:
self.after(self._current_error) self.after(self._current_error)
except: except Exception:
log.exception('Calling the after function failed.') log.exception('Calling the after function failed.')
def stop(self): def stop(self):

2
discord/shard.py

@ -282,7 +282,7 @@ class AutoShardedClient(Client):
for vc in self.voice_clients: for vc in self.voice_clients:
try: try:
await vc.disconnect() await vc.disconnect()
except: except Exception:
pass pass
to_close = [shard.ws.close() for shard in self.shards.values()] to_close = [shard.ws.close() for shard in self.shards.values()]

2
discord/voice_client.py

@ -177,7 +177,7 @@ class VoiceClient:
if self.socket: if self.socket:
try: try:
self.socket.close() self.socket.close()
except: except Exception:
pass pass
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Loading…
Cancel
Save