-
-
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 main branch #68
base: main
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.
guild = client.get_guild(obj) | ||
if guild: | ||
if guild := client.get_guild(obj): |
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 get_pointer
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
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
)
entries = [] | ||
entries = [ | ||
'- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format( | ||
sys.version_info | ||
) | ||
] | ||
|
||
entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info)) | ||
version_info = discord.version_info | ||
entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info)) | ||
if version_info.releaselevel != 'final': | ||
pkg = pkg_resources.get_distribution('discord.py') | ||
if pkg: | ||
if pkg := pkg_resources.get_distribution('discord.py'): |
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:
- Merge append into list declaration (
merge-list-append
) - Swap positions of nested conditionals [×2] (
swap-nested-ifs
) - 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 179-179
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
)
setattr(self, '_' + key, 0) | ||
setattr(self, f'_{key}', 0) | ||
else: | ||
setattr(self, '_' + key, dt.timestamp() * 1000.0) | ||
setattr(self, f'_{key}', dt.timestamp() * 1000.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 Game._extract_timestamp
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
return 'https://i.scdn.co/image/' + album_image_id | ||
return f'https://i.scdn.co/image/{album_image_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 Spotify.album_cover_url
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
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
)
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 user.is_avatar_animated(): | ||
raise InvalidArgument("non animated avatars 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_avatar
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_STATIC_FORMATS)) | ||
raise InvalidArgument(f"format must be None or 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_icon
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise InvalidArgument("format must be None or one of {}".format(VALID_STATIC_FORMATS)) | ||
raise InvalidArgument(f"format must be None or 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_cover_image
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise InvalidArgument("format must be one of {}".format(VALID_STATIC_FORMATS)) | ||
raise InvalidArgument(f"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_image
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise InvalidArgument("format must be one of {}".format(VALID_AVATAR_FORMATS)) | ||
raise InvalidArgument(f"format must be one of {VALID_AVATAR_FORMATS}") | ||
if format == "gif" and not guild.is_icon_animated(): | ||
raise InvalidArgument("non animated guild icons 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_guild_icon
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 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
)
return 'Direct Message with %s' % self.recipient | ||
return f'Direct Message with {self.recipient}' |
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 DMChannel.__str__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return '<ClientEventTask {}>'.format(' '.join('%s=%s' % t for t in info)) | ||
return f"<ClientEventTask {' '.join('%s=%s' % t for t in info)}>" |
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 _ClientEventTask.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if self.ws: | ||
return self.ws.is_ratelimited() | ||
return False | ||
return self.ws.is_ratelimited() if self.ws else False |
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 Client.is_ws_ratelimited
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
)
method = 'on_' + event | ||
method = f'on_{event}' | ||
|
||
listeners = self._listeners.get(event) | ||
if listeners: | ||
if listeners := self._listeners.get(event): |
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 Client.dispatch
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify sequence length comparison (
simplify-len-comparison
)
print('Ignoring exception in {}'.format(event_method), file=sys.stderr) | ||
print(f'Ignoring exception in {event_method}', file=sys.stderr) |
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 Client.on_error
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise TypeError("unexpected keyword argument(s) %s" % list(kwargs.keys())) | ||
raise TypeError(f"unexpected keyword argument(s) {list(kwargs.keys())}") |
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 Client.start
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
for channel in guild.channels: | ||
yield channel | ||
yield from guild.channels |
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 Client.get_all_channels
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for member in guild.members: | ||
yield member | ||
yield from guild.members |
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 Client.get_all_members
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
if activity is not None: | ||
me.activities = (activity,) | ||
else: | ||
me.activities = () | ||
|
||
me.activities = (activity, ) if activity is not None else () |
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 Client.change_presence
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
channel = factory(me=self.user, data=data, state=self._connection) | ||
else: | ||
guild_id = int(data['guild_id']) | ||
guild = self.get_guild(guild_id) or Object(id=guild_id) | ||
channel = factory(guild=guild, state=self._connection, data=data) | ||
|
||
return channel | ||
return factory(me=self.user, data=data, state=self._connection) | ||
guild_id = int(data['guild_id']) | ||
guild = self.get_guild(guild_id) or Object(id=guild_id) | ||
return factory(guild=guild, state=self._connection, data=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 Client.fetch_channel
refactored with the following changes:
- Lift return into if (
lift-return-into-if
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
base = [] | ||
base.extend([{'type': 1, 'components': [obj.to_dict() for obj in self.components[five:5:]]} for five in | ||
range(0, len(self.components), 5)]) | ||
base = [ | ||
{ | ||
'type': 1, | ||
'components': [obj.to_dict() for obj in self.components[five:5:]], | ||
} | ||
for five in range(0, len(self.components), 5) | ||
] | ||
objects = len([i['components'] for i in base]) | ||
if any([any([part['type'] == 2]) and any([part['type'] == 3]) for part in base]): | ||
if any( | ||
any([part['type'] == 2]) and any([part['type'] == 3]) for part in base | ||
): | ||
raise InvalidArgument('An ActionRow containing a select menu cannot also contain buttons') | ||
if any([any([part['type'] == 3]) and len(part) > 1 for part in base]): | ||
if any(any([part['type'] == 3]) and len(part) > 1 for part in base): | ||
raise InvalidArgument('An ActionRow can contain only one SelectMenu') | ||
if any([len(ar['components']) < 1 for ar in base]): | ||
if any(len(ar['components']) < 1 for ar in 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 ActionRow.to_dict
refactored with the following changes:
- Merge extend into list declaration (
merge-list-extend
) - Replace unneeded comprehension with generator [×4] (
comprehension-to-generator
) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
raise IndexError('component index %s out of range' % index) | ||
raise IndexError(f'component index {index} out of range') |
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 ActionRow.set_component_at
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
raise IndexError('component index %s out of range' % index) | ||
raise IndexError(f'component index {index} out of range') |
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 ActionRow.disable_component_at
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return InvalidArgument("%s could not be implemented as an ActionRow" % data) | ||
else: | ||
components = [_component_factory(component) for component in data.get('components', [])] | ||
return cls(*components) | ||
return InvalidArgument(f"{data} could not be implemented as an ActionRow") | ||
components = [_component_factory(component) for component in data.get('components', [])] | ||
return cls(*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 ActionRow.from_dict
refactored with the following changes:
- Swap if/else branches [×2] (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return 'EmbedProxy(%s)' % ', '.join(('%s=%r' % (k, v) for k, v in self.__dict__.items() if not k.startswith('_'))) | ||
return f"EmbedProxy({', '.join('%s=%r' % (k, v) for k, v in self.__dict__.items() if not k.startswith('_'))})" |
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 EmbedProxy.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Branch
main
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
main
branch, then run:Help us improve this pull request!