Modernize code to use f-strings

This also removes the encoding on the top, since Python 3 does it by
default. It also changes some methods to use `yield from`.
This commit is contained in:
Rapptz
2021-04-04 04:40:19 -04:00
parent 9fc2ab9c99
commit 9d39b135f4
67 changed files with 262 additions and 378 deletions

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
"""
The MIT License (MIT)
@ -196,16 +194,16 @@ class Activity(BaseActivity):
def __repr__(self):
attrs = (
'type',
'name',
'url',
'details',
'application_id',
'session_id',
'emoji',
('type', self.type),
('name', self.name),
('url', self.url),
('details', self.details),
('application_id', self.application_id),
('session_id', self.session_id),
('emoji', self.emoji),
)
mapped = ' '.join('%s=%r' % (attr, getattr(self, attr)) for attr in attrs)
return '<Activity %s>' % mapped
inner = ' '.join('%s=%r' % t for t in attrs)
return f'<Activity {inner}>'
def to_dict(self):
ret = {}
@ -250,7 +248,7 @@ class Activity(BaseActivity):
except KeyError:
return None
else:
return Asset.BASE + '/app-assets/{0}/{1}.png'.format(self.application_id, large_image)
return Asset.BASE + f'/app-assets/{self.application_id}/{large_image}.png'
@property
def small_image_url(self):
@ -263,7 +261,7 @@ class Activity(BaseActivity):
except KeyError:
return None
else:
return Asset.BASE + '/app-assets/{0}/{1}.png'.format(self.application_id, small_image)
return Asset.BASE + f'/app-assets/{self.application_id}/{small_image}.png'
@property
def large_image_text(self):
"""Optional[:class:`str`]: Returns the large image asset hover text of this activity if applicable."""
@ -362,7 +360,7 @@ class Game(BaseActivity):
return str(self.name)
def __repr__(self):
return '<Game name={0.name!r}>'.format(self)
return f'<Game name={self.name!r}>'
def to_dict(self):
timestamps = {}
@ -455,7 +453,7 @@ class Streaming(BaseActivity):
return str(self.name)
def __repr__(self):
return '<Streaming name={0.name!r}>'.format(self)
return f'<Streaming name={self.name!r}>'
@property
def twitch_name(self):
@ -700,7 +698,7 @@ class CustomActivity(BaseActivity):
elif isinstance(emoji, PartialEmoji):
self.emoji = emoji
else:
raise TypeError('Expected str, PartialEmoji, or None, received {0!r} instead.'.format(type(emoji)))
raise TypeError(f'Expected str, PartialEmoji, or None, received {type(emoji)!r} instead.')
@property
def type(self):
@ -739,7 +737,7 @@ class CustomActivity(BaseActivity):
def __str__(self):
if self.emoji:
if self.name:
return '%s %s' % (self.emoji, self.name)
return f'{self.emoji} {self.name}'
return str(self.emoji)
else:
return str(self.name)