Code optimisations and refactoring via Sourcery

This commit is contained in:
Nadir Chowdhury
2021-02-25 02:26:51 +00:00
committed by GitHub
parent e090ee4308
commit 63ec23bac2
18 changed files with 47 additions and 90 deletions

View File

@@ -165,9 +165,8 @@ class BotBase(GroupMixin):
return
cog = context.cog
if cog:
if Cog._get_overridden_method(cog.cog_command_error) is not None:
return
if cog and Cog._get_overridden_method(cog.cog_command_error) is not None:
return
print('Ignoring exception in command {}:'.format(context.command), file=sys.stderr)
traceback.print_exception(type(exception), exception, exception.__traceback__, file=sys.stderr)
@@ -770,7 +769,7 @@ class BotBase(GroupMixin):
self._remove_module_references(lib.__name__)
self._call_module_finalizers(lib, name)
self.load_extension(name)
except Exception as e:
except Exception:
# if the load failed, the remnants should have been
# cleaned from the load_extension function call
# so let's load it from our old compiled library.

View File

@@ -96,7 +96,7 @@ class CogMeta(type):
def __new__(cls, *args, **kwargs):
name, bases, attrs = args
attrs['__cog_name__'] = kwargs.pop('name', name)
attrs['__cog_settings__'] = command_attrs = kwargs.pop('command_attrs', {})
attrs['__cog_settings__'] = kwargs.pop('command_attrs', {})
description = kwargs.pop('description', None)
if description is None:
@@ -126,7 +126,7 @@ class CogMeta(type):
commands[elem] = value
elif inspect.iscoroutinefunction(value):
try:
is_listener = getattr(value, '__cog_listener__')
getattr(value, '__cog_listener__')
except AttributeError:
continue
else:
@@ -192,7 +192,7 @@ class Cog(metaclass=CogMeta):
parent = lookup[parent.qualified_name]
# Update our parent's reference to our self
removed = parent.remove_command(command.name)
parent.remove_command(command.name)
parent.add_command(command)
return self

View File

@@ -313,7 +313,7 @@ class Context(discord.abc.Messageable):
entity = bot.get_cog(entity) or bot.get_command(entity)
try:
qualified_name = entity.qualified_name
entity.qualified_name
except AttributeError:
# if we're here then it's not a cog, group, or command.
return None

View File

@@ -715,9 +715,8 @@ class Command(_BaseCommand):
except RuntimeError:
break
if not self.ignore_extra:
if not view.eof:
raise TooManyArguments('Too many arguments passed to ' + self.qualified_name)
if not self.ignore_extra and not view.eof:
raise TooManyArguments('Too many arguments passed to ' + self.qualified_name)
async def call_before_hooks(self, ctx):
# now that we're done preparing we can call the pre-command hooks