[lint] Limit unneccessarily broad except clauses

Add exception qualifier(s) to bare except clauses swallowing exceptions.
This commit is contained in:
Hornwitser 2018-06-22 15:12:56 +02:00 committed by Rapptz
parent 860d6a9ace
commit a71b3b5fa0
11 changed files with 19 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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