diff --git a/discord/abc.py b/discord/abc.py index 18e8a0627..7f895b525 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -279,7 +279,7 @@ class GuildChannel(Protocol): perms = [] for target, perm in overwrites.items(): if not isinstance(perm, PermissionOverwrite): - raise InvalidArgument('Expected PermissionOverwrite received {0.__name__}'.format(type(perm))) + raise InvalidArgument(f'Expected PermissionOverwrite received {perm.__class__.__name__}') allow, deny = perm.pair() payload = { diff --git a/discord/activity.py b/discord/activity.py index 7c46a6600..f91288172 100644 --- a/discord/activity.py +++ b/discord/activity.py @@ -584,7 +584,7 @@ class Spotify: return 'Spotify' def __repr__(self): - return ''.format(self) + return f'' @property def title(self): @@ -738,7 +738,7 @@ class CustomActivity(BaseActivity): return str(self.name) def __repr__(self): - return ''.format(self) + return f'' def create_activity(data): diff --git a/discord/appinfo.py b/discord/appinfo.py index 066cf6f02..6f1754ffa 100644 --- a/discord/appinfo.py +++ b/discord/appinfo.py @@ -31,6 +31,7 @@ __all__ = ( 'AppInfo', ) + class AppInfo: """Represents the application info for the bot provided by Discord. @@ -95,10 +96,25 @@ class AppInfo: .. versionadded:: 1.3 """ - __slots__ = ('_state', 'description', 'id', 'name', 'rpc_origins', - 'bot_public', 'bot_require_code_grant', 'owner', 'icon', - 'summary', 'verify_key', 'team', 'guild_id', 'primary_sku_id', - 'slug', 'cover_image') + + __slots__ = ( + '_state', + 'description', + 'id', + 'name', + 'rpc_origins', + 'bot_public', + 'bot_require_code_grant', + 'owner', + 'icon', + 'summary', + 'verify_key', + 'team', + 'guild_id', + 'primary_sku_id', + 'slug', + 'cover_image', + ) def __init__(self, state, data): self._state = state @@ -125,8 +141,11 @@ class AppInfo: self.cover_image = data.get('cover_image') def __repr__(self): - return '<{0.__class__.__name__} id={0.id} name={0.name!r} description={0.description!r} public={0.bot_public} ' \ - 'owner={0.owner!r}>'.format(self) + return ( + f'<{self.__class__.__name__} id={self.id} name={self.name!r} ' + f'description={self.description!r} public={self.bot_public} ' + f'owner={self.owner!r}>' + ) @property def icon_url(self): @@ -166,7 +185,6 @@ class AppInfo: """ return Asset._from_icon(self._state, self, 'app', format=format, size=size) - @property def cover_image_url(self): """:class:`.Asset`: Retrieves the cover image on a store embed. diff --git a/discord/asset.py b/discord/asset.py index db3b8967c..da1788d1a 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -88,7 +88,7 @@ class Asset: if format is None: format = 'gif' if user.is_avatar_animated() else static_format - return cls(state, '/avatars/{0.id}/{0.avatar}.{1}?size={2}'.format(user, format, size)) + return cls(state, f'/avatars/{user.id}/{user.avatar}.{format}?size={size}') @classmethod def _from_icon(cls, state, object, path, *, format='webp', size=1024): @@ -100,7 +100,7 @@ class Asset: if format not in VALID_STATIC_FORMATS: raise InvalidArgument(f"format must be None or one of {VALID_STATIC_FORMATS}") - url = '/{0}-icons/{1.id}/{1.icon}.{2}?size={3}'.format(path, object, format, size) + url = f'/{path}-icons/{object.id}/{object.icon}.{format}?size={size}' return cls(state, url) @classmethod @@ -113,7 +113,7 @@ class Asset: if format not in VALID_STATIC_FORMATS: raise InvalidArgument(f"format must be None or one of {VALID_STATIC_FORMATS}") - url = '/app-assets/{0.id}/store/{0.cover_image}.{1}?size={2}'.format(obj, format, size) + url = f'/app-assets/{obj.id}/store/{obj.cover_image}.{format}?size={size}' return cls(state, url) @classmethod @@ -126,8 +126,7 @@ class Asset: if hash is None: return cls(state) - url = '/{key}/{0}/{1}.{2}?size={3}' - return cls(state, url.format(id, hash, format, size, key=key)) + return cls(state, f'/{key}/{id}/{hash}.{format}?size={size}') @classmethod def _from_guild_icon(cls, state, guild, *, format=None, static_format='webp', size=1024): @@ -146,14 +145,14 @@ class Asset: if format is None: format = 'gif' if guild.is_icon_animated() else static_format - return cls(state, '/icons/{0.id}/{0.icon}.{1}?size={2}'.format(guild, format, size)) + return cls(state, f'/icons/{guild.id}/{guild.icon}.{format}?size={size}') @classmethod def _from_sticker_url(cls, state, sticker, *, size=1024): if not utils.valid_icon_size(size): raise InvalidArgument("size must be a power of 2 between 16 and 4096") - return cls(state, '/stickers/{0.id}/{0.image}.png?size={2}'.format(sticker, format, size)) + return cls(state, f'/stickers/{sticker.id}/{sticker.image}.png?size={size}') @classmethod def _from_emoji(cls, state, emoji, *, format=None, static_format='png'): diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 745f89d10..ea97eb745 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -301,7 +301,7 @@ class AuditLogEntry(Hashable): return self.guild.get_member(user_id) or self._users.get(user_id) def __repr__(self): - return ''.format(self) + return f'' @utils.cached_property def created_at(self): diff --git a/discord/channel.py b/discord/channel.py index 5c6eed1ed..314485d65 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -320,7 +320,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) - await channel.send('Deleted {} message(s)'.format(len(deleted))) + await channel.send(f'Deleted {len(deleted)} message(s)') Parameters ----------- @@ -504,7 +504,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): raise ClientException('The channel must be a news channel.') if not isinstance(destination, TextChannel): - raise InvalidArgument('Expected TextChannel received {0.__name__}'.format(type(destination))) + raise InvalidArgument(f'Expected TextChannel received {destination.__class__.__name__}') from .webhook import Webhook data = await self._state.http.follow_webhook(self.id, webhook_channel_id=destination.id, reason=reason) @@ -896,7 +896,7 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): self._update(guild, data) def __repr__(self): - return ''.format(self) + return f'' def _update(self, guild, data): self.guild = guild @@ -1092,7 +1092,7 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): self._update(guild, data) def __repr__(self): - return ''.format(self) + return f'' def _update(self, guild, data): self.guild = guild @@ -1218,7 +1218,7 @@ class DMChannel(discord.abc.Messageable, Hashable): return f'Direct Message with {self.recipient}' def __repr__(self): - return ''.format(self) + return f'' @property def type(self): @@ -1354,7 +1354,7 @@ class GroupChannel(discord.abc.Messageable, Hashable): return ', '.join(map(lambda x: x.name, self.recipients)) def __repr__(self): - return ''.format(self) + return f'' @property def type(self): diff --git a/discord/client.py b/discord/client.py index 32560099b..cae978f12 100644 --- a/discord/client.py +++ b/discord/client.py @@ -849,7 +849,7 @@ class Client: return m.content == 'hello' and m.channel == channel msg = await client.wait_for('message', check=check) - await channel.send('Hello {.author}!'.format(msg)) + await channel.send(f'Hello {msg.author}!') Waiting for a thumbs up reaction from the message author: :: diff --git a/discord/emoji.py b/discord/emoji.py index 02c0ddc8e..bf7982ab7 100644 --- a/discord/emoji.py +++ b/discord/emoji.py @@ -111,11 +111,11 @@ class Emoji(_EmojiTag): def __str__(self): if self.animated: - return ''.format(self) - return "<:{0.name}:{0.id}>".format(self) + return f'' + return f'<:{self.name}:{self.id}>' def __repr__(self): - return ''.format(self) + return f'' def __eq__(self, other): return isinstance(other, _EmojiTag) and self.id == other.id diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 59f11c74f..dabe14398 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -846,7 +846,7 @@ class BotBase(GroupMixin): raise raise TypeError("command_prefix must be plain string, iterable of strings, or callable " - "returning either of these, not {}".format(ret.__class__.__name__)) + f"returning either of these, not {ret.__class__.__name__}") if not ret: raise ValueError("Iterable command_prefix must contain at least one prefix") @@ -907,13 +907,13 @@ class BotBase(GroupMixin): except TypeError: if not isinstance(prefix, list): raise TypeError("get_prefix must return either a string or a list of string, " - "not {}".format(prefix.__class__.__name__)) + f"not {prefix.__class__.__name__}") # It's possible a bad command_prefix got us here. for value in prefix: if not isinstance(value, str): raise TypeError("Iterable command_prefix or list returned from get_prefix must " - "contain only strings, not {}".format(value.__class__.__name__)) + f"contain only strings, not {value.__class__.__name__}") # Getting here shouldn't happen raise diff --git a/discord/ext/commands/cooldowns.py b/discord/ext/commands/cooldowns.py index 7cfc9fd74..fc438c9f7 100644 --- a/discord/ext/commands/cooldowns.py +++ b/discord/ext/commands/cooldowns.py @@ -131,7 +131,7 @@ class Cooldown: return Cooldown(self.rate, self.per, self.type) def __repr__(self): - return ''.format(self) + return f'' class CooldownMapping: def __init__(self, original): @@ -202,7 +202,7 @@ class _Semaphore: self._waiters = deque() def __repr__(self): - return '<_Semaphore value={0.value} waiters={1}>'.format(self, len(self._waiters)) + return f'<_Semaphore value={self.value} waiters={len(self._waiters)}>' def locked(self): return self.value == 0 @@ -259,7 +259,7 @@ class MaxConcurrency: return self.__class__(self.number, per=self.per, wait=self.wait) def __repr__(self): - return ''.format(self) + return f'' def get_key(self, message): return self.per.get_key(message) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 0de14b458..a570ee48c 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -695,15 +695,13 @@ class Command(_BaseCommand): try: next(iterator) except StopIteration: - fmt = 'Callback for {0.name} command is missing "self" parameter.' - raise discord.ClientException(fmt.format(self)) + raise discord.ClientException(f'Callback for {self.name} command is missing "self" parameter.') # next we have the 'ctx' as the next parameter try: next(iterator) except StopIteration: - fmt = 'Callback for {0.name} command is missing "ctx" parameter.' - raise discord.ClientException(fmt.format(self)) + raise discord.ClientException(f'Callback for {self.name} command is missing "ctx" parameter.') for name, param in iterator: if param.kind == param.POSITIONAL_OR_KEYWORD or param.kind == param.POSITIONAL_ONLY: @@ -2046,7 +2044,7 @@ def before_invoke(coro): @commands.before_invoke(record_usage) @commands.command() async def when(self, ctx): # Output: used when at