-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: developer
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
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] |
There was a problem hiding this comment.
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:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
version = importlib_metadata.version('discord.py-message-components') | ||
if version: | ||
if version := importlib_metadata.version( | ||
'discord.py-message-components' | ||
): |
There was a problem hiding this comment.
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:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
_base_table.update((chr(i), None) for i in range(32)) | ||
_base_table |= ((chr(i), None) for i in range(32)) |
There was a problem hiding this comment.
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:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
parser.error('could not create our bot directory ({})'.format(exc)) | ||
parser.error(f'could not create our bot directory ({exc})') |
There was a problem hiding this comment.
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:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting
)
print('warning: could not create cogs directory ({})'.format(exc)) | ||
print(f'warning: could not create cogs directory ({exc})') |
There was a problem hiding this comment.
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:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
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) |
There was a problem hiding this comment.
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:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if 'url' in data: | ||
return Streaming(**data) | ||
return Activity(**data) | ||
return Streaming(**data) if 'url' in data else Activity(**data) |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
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 |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition [×2] (
remove-unnecessary-else
) - Swap if/else branches [×4] (
swap-if-else-branches
)
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}>' |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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) |
There was a problem hiding this comment.
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:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
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 |
There was a problem hiding this comment.
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:
- Replace if statement with if expression (
assign-if-exp
)
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)}.' | ||
) |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return '<SlashCommandOptionChoice name=%s, value=%s>' % (self.name, self.value) | ||
return f'<SlashCommandOptionChoice name={self.name}, value={self.value}>' |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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 |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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)}.' | ||
) |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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}>" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
converter = origin_option.converter | ||
if converter: | ||
if converter := origin_option.converter: |
There was a problem hiding this comment.
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:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
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) |
There was a problem hiding this comment.
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:
- Swap if/else to remove empty if body (
remove-pass-body
) - Inline variable that is immediately returned [×3] (
inline-immediately-returned-variable
) - Replace call to format with f-string (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if not result and not required: | ||
return param.default | ||
return result | ||
return param.default if not result and not required else result |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
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])}>" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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)}.' | ||
) |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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)}.' | ||
) |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
'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)}.' | ||
) |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
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])}>" |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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 |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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}") |
There was a problem hiding this comment.
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:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
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}") |
There was a problem hiding this comment.
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:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
if self._url: | ||
return len(self.BASE + self._url) | ||
return 0 | ||
return len(self.BASE + self._url) if self._url else 0 |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if data is None: | ||
return None | ||
return entry._get_member(int(data)) | ||
return None if data is None else entry._get_member(int(data)) |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if data is None: | ||
return None | ||
return entry._get_member(int(data)) | ||
return None if data is None else entry._get_member(int(data)) |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
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:Help us improve this pull request!