Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored developer branch #69

Open
wants to merge 1 commit into
base: developer
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented May 24, 2023

Branch developer refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the developer branch, then run:

git fetch origin sourcery/developer
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from mccoderpy May 24, 2023 09:24
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -11 to +13
version += re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1)
version += re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE
)[1]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-11 refactored with the following changes:

Comment on lines -45 to +47
version = importlib_metadata.version('discord.py-message-components')
if version:
if version := importlib_metadata.version(
'discord.py-message-components'
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function show_version refactored with the following changes:

Comment on lines -180 to +181
_base_table.update((chr(i), None) for i in range(32))
_base_table |= ((chr(i), None) for i in range(32))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 180-180 refactored with the following changes:

Comment on lines -209 to +210
parser.error('could not create our bot directory ({})'.format(exc))
parser.error(f'could not create our bot directory ({exc})')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function newbot refactored with the following changes:

Comment on lines -248 to +249
print('warning: could not create cogs directory ({})'.format(exc))
print(f'warning: could not create cogs directory ({exc})')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function newcog refactored with the following changes:

Comment on lines -754 to +753
if self.emoji:
if self.name:
return '%s %s' % (self.emoji, self.name)
return str(self.emoji)
else:
if not self.emoji:
return str(self.name)
return f'{self.emoji} {self.name}' if self.name else str(self.emoji)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CustomActivity.__str__ refactored with the following changes:

Comment on lines -782 to +776
if 'url' in data:
return Streaming(**data)
return Activity(**data)
return Streaming(**data) if 'url' in data else Activity(**data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_activity refactored with the following changes:

Comment on lines -241 to +248
else:
if (default.value if default is Locale else default) not in self.__slots__:
return default
else:
try:
self[default.value if default is Locale else default]
except KeyError: # not a locale so return it
return default
if (
default.value if default is Locale else default
) not in self.__slots__:
return default
try:
self[default.value if default is Locale else default]
except KeyError: # not a locale so return it
return default
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Localizations.from_target refactored with the following changes:

return '<%s name=%s, id=%s, disabled=%s>' % (self.__class__.__name__, self.name, self.id, self.disabled)
return f'<{self.__class__.__name__} name={self.name}, id={self.id}, disabled={self.disabled}>'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApplicationCommand.__repr__ refactored with the following changes:

Comment on lines -383 to -386
checks = getattr(check_func, '__commands_checks__', getattr(self.func, '__commands_checks__', []))
if not checks:
if checks := getattr(
check_func,
'__commands_checks__',
getattr(self.func, '__commands_checks__', []),
):
return await async_all(check(args[0]) for check in checks)
else:
return True
return await async_all(check(args[0]) for check in checks)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApplicationCommand.can_run refactored with the following changes:

Comment on lines -494 to +498
if self.guild_id != 0:
guild_id = self.guild_id
else:
guild_id = None
guild_id = self.guild_id if self.guild_id != 0 else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApplicationCommand.delete refactored with the following changes:

Comment on lines -530 to +533
raise ValueError('The name of a choice must bee between 1 and 100 characters long, got %s.' % len(name))
raise ValueError(
f'The name of a choice must bee between 1 and 100 characters long, got {len(name)}.'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommandOptionChoice.__init__ refactored with the following changes:

Comment on lines -536 to +539
return '<SlashCommandOptionChoice name=%s, value=%s>' % (self.name, self.value)
return f'<SlashCommandOptionChoice name={self.name}, value={self.value}>'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommandOptionChoice.__repr__ refactored with the following changes:

Comment on lines -539 to -544
base = {
return {
'name': str(self.name),
'value': self.value,
'name_localizations': self.name_localizations.to_dict()
'name_localizations': self.name_localizations.to_dict(),
}
return base
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommandOptionChoice.to_dict refactored with the following changes:

Comment on lines -661 to +665
raise ValueError('The description must be between 1 and 100 characters long, got %s.' % len(description))
raise ValueError(
f'The description must be between 1 and 100 characters long, got {len(description)}.'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommandOption.__init__ refactored with the following changes:

Comment on lines -1220 to +1217
return '<SlashCommand name=%s, description=%s, default_member_permissions=%s, options=%s, guild_id=%s disabled=%s, id=%s>' \
% (self.name,
self.description,
self.default_member_permissions,
self.options or self.sub_commands,
self.guild_id or 'None',
self.disabled,
self.id)
return f"<SlashCommand name={self.name}, description={self.description}, default_member_permissions={self.default_member_permissions}, options={self.options or self.sub_commands}, guild_id={self.guild_id or 'None'} disabled={self.disabled}, id={self.id}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommand.__repr__ refactored with the following changes:

Comment on lines -1411 to +1401
converter = origin_option.converter
if converter:
if converter := origin_option.converter:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SlashCommand._parse_arguments refactored with the following changes:

Comment on lines -1468 to +1472
if module.startswith('discord.') and module.endswith('converter'):
pass
else:
converter = getattr(converters, converter.__name__ + 'Converter', converter)
if not module.startswith('discord.') or not module.endswith(
'converter'
):
converter = getattr(converters, f'{converter.__name__}Converter', converter)

try:
if inspect.isclass(converter):
if issubclass(converter, converters.Converter):
instance = converter()
ret = await instance.convert(ctx, argument)
return ret
return await instance.convert(ctx, argument)
else:
method = getattr(converter, 'convert', None)
if method is not None and inspect.ismethod(method):
ret = await method(ctx, argument)
return ret
return await method(ctx, argument)
elif isinstance(converter, converters.Converter):
ret = await converter.convert(ctx, argument)
return ret
return await converter.convert(ctx, argument)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _actual_conversion refactored with the following changes:

Comment on lines -1554 to +1542
if not result and not required:
return param.default
return result
return param.default if not result and not required else result
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _transform_greedy_pos refactored with the following changes:

Comment on lines -1582 to +1568
return '<GuildOnlySlashCommand name=%s, description=%s, default_member_permissions=%s, options=%s, guild_ids=%s>' \
% (self.name,
self.description,
self.default_member_permissions,
self.options,
', '.join([str(g) for g in self.guild_ids])
)
return f"<GuildOnlySlashCommand name={self.name}, description={self.description}, default_member_permissions={self.default_member_permissions}, options={self.options}, guild_ids={', '.join([str(g) for g in self.guild_ids])}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GuildOnlySlashCommand.__repr__ refactored with the following changes:

Comment on lines -1645 to +1627
raise ValueError('The name of the User-Command has to be 1-32 characters long, got %s.' % len(name))
raise ValueError(
f'The name of the User-Command has to be 1-32 characters long, got {len(name)}.'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UserCommand.__init__ refactored with the following changes:

Comment on lines -1696 to +1680
raise ValueError('The name of the Message-Command has to be 1-32 characters long, got %s.' % len(name))
raise ValueError(
f'The name of the Message-Command has to be 1-32 characters long, got {len(name)}.'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MessageCommand.__init__ refactored with the following changes:

Comment on lines -1739 to +1728
'The description of the Sub-Command-Group must be 1-100 characters long, got %s.' % len(description)
)
f'The description of the Sub-Command-Group must be 1-100 characters long, got {len(description)}.'
)
if 25 < len(commands) < 1:
raise ValueError('A Sub-Command-Group needs 1-25 sub-sub_commands, got %s.' % len(commands))
raise ValueError(
f'A Sub-Command-Group needs 1-25 sub-sub_commands, got {len(commands)}.'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SubCommandGroup.__init__ refactored with the following changes:

Comment on lines -1758 to +1744
return '<SubCommandGroup parent=%s, name=%s, description=%s, sub_commands=%s>' % \
(self.parent.name,
self.name,
self.description,
', '.join([sub_cmd.name for sub_cmd in self.sub_commands])
)
return f"<SubCommandGroup parent={self.parent.name}, name={self.name}, description={self.description}, sub_commands={', '.join([sub_cmd.name for sub_cmd in self.sub_commands])}>"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SubCommandGroup.__repr__ refactored with the following changes:

Comment on lines -1795 to -1803
base = {
return {
'type': 2,
'name': str(self.name),
'name_localizations': self.name_localizations.to_dict(),
'description': str(self.description),
'description_localizations': self.description_localizations.to_dict(),
'options': [c.to_dict() for c in self.sub_commands]
'options': [c.to_dict() for c in self.sub_commands],
}
return base
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SubCommandGroup.to_dict refactored with the following changes:

Comment on lines -346 to +350
raise InvalidArgument("format must be None or one of {}".format(VALID_AVATAR_FORMATS))
raise InvalidArgument(f"format must be None or one of {VALID_AVATAR_FORMATS}")
if format == "gif" and not emoji.animated:
raise InvalidArgument("non animated emoji's do not support gif format")
if static_format not in VALID_STATIC_FORMATS:
raise InvalidArgument("static_format must be one of {}".format(VALID_STATIC_FORMATS))
raise InvalidArgument(f"static_format must be one of {VALID_STATIC_FORMATS}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Asset._from_emoji refactored with the following changes:

Comment on lines -368 to +370
raise InvalidArgument("format must be None or one of {}".format(VALID_AVATAR_FORMATS))
raise InvalidArgument(f"format must be None or one of {VALID_AVATAR_FORMATS}")
if static_format not in VALID_STATIC_FORMATS:
raise InvalidArgument("static_format must be one of {}".format(VALID_STATIC_FORMATS))
raise InvalidArgument(f"static_format must be one of {VALID_STATIC_FORMATS}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Asset._from_guild_event refactored with the following changes:

if self._url:
return len(self.BASE + self._url)
return 0
return len(self.BASE + self._url) if self._url else 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Asset.__len__ refactored with the following changes:

if data is None:
return None
return entry._get_member(int(data))
return None if data is None else entry._get_member(int(data))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _transform_owner_id refactored with the following changes:

Comment on lines -63 to +61
if data is None:
return None
return entry._get_member(int(data))
return None if data is None else entry._get_member(int(data))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _transform_inviter_id refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants