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 main branch #68

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

Sourcery refactored main branch #68

wants to merge 1 commit into from

Conversation

sourcery-ai[bot]
Copy link

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

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:

git fetch origin sourcery/main
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:13
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.

guild = client.get_guild(obj)
if guild:
if guild := client.get_guild(obj):
Copy link
Author

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:

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 -38 to +47
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'):
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 -179 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 179-179 refactored with the following changes:

Comment on lines -208 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 -335 to +334
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)
Copy link
Author

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:

Comment on lines -627 to +624
return 'https://i.scdn.co/image/' + album_image_id
return f'https://i.scdn.co/image/{album_image_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 Spotify.album_cover_url refactored with the following changes:

Comment on lines -740 to +739
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 -768 to +762
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 -77 to +81
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}")
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_avatar refactored with the following changes:

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}")
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_icon refactored with the following changes:

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}")
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_cover_image refactored with the following changes:

raise InvalidArgument("format must be one of {}".format(VALID_STATIC_FORMATS))
raise InvalidArgument(f"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_image refactored with the following changes:

Comment on lines -135 to +139
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}")
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_icon refactored with the following changes:

Comment on lines -159 to +163
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:

return 'Direct Message with %s' % self.recipient
return f'Direct Message with {self.recipient}'
Copy link
Author

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:

return '<ClientEventTask {}>'.format(' '.join('%s=%s' % t for t in info))
return f"<ClientEventTask {' '.join('%s=%s' % t for t in info)}>"
Copy link
Author

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:

if self.ws:
return self.ws.is_ratelimited()
return False
return self.ws.is_ratelimited() if self.ws else False
Copy link
Author

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:

method = 'on_' + event
method = f'on_{event}'

listeners = self._listeners.get(event)
if listeners:
if listeners := self._listeners.get(event):
Copy link
Author

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:

Comment on lines -412 to +407
print('Ignoring exception in {}'.format(event_method), file=sys.stderr)
print(f'Ignoring exception in {event_method}', file=sys.stderr)
Copy link
Author

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:

Comment on lines -669 to +664
raise TypeError("unexpected keyword argument(s) %s" % list(kwargs.keys()))
raise TypeError(f"unexpected keyword argument(s) {list(kwargs.keys())}")
Copy link
Author

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:

Comment on lines -868 to +863
for channel in guild.channels:
yield channel
yield from guild.channels
Copy link
Author

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)

Comment on lines -886 to +880
for member in guild.members:
yield member
yield from guild.members
Copy link
Author

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)

Comment on lines -1186 to +1179
if activity is not None:
me.activities = (activity,)
else:
me.activities = ()

me.activities = (activity, ) if activity is not None else ()
Copy link
Author

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:

Comment on lines -1583 to +1575
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)
Copy link
Author

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:

Comment on lines -542 to +549
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):
Copy link
Author

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:

Comment on lines -625 to +624
raise IndexError('component index %s out of range' % index)
raise IndexError(f'component index {index} out of range')
Copy link
Author

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:

Comment on lines -648 to +647
raise IndexError('component index %s out of range' % index)
raise IndexError(f'component index {index} out of range')
Copy link
Author

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:

Comment on lines -768 to +769
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)
Copy link
Author

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:

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('_'))})"
Copy link
Author

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:

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