Skip to content

Commit 315082f

Browse files
authored
Run black with experimental string processing (#1725)
1 parent 0de0652 commit 315082f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+317
-153
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ repos:
2727
rev: 22.10.0
2828
hooks:
2929
- id: black
30+
# See https://github.com/psf/black/issues/2188#issuecomment-1289317647 for why we can't use the --preview flag.
3031
args: [--safe, --quiet]
31-
# - repo: https://github.com/Pierre-Sassoulas/black-disable-checker
32-
# rev: 1.0.1
33-
# hooks:
34-
# - id: black-disable-checker
32+
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker
33+
rev: 1.0.1
34+
hooks:
35+
- id: black-disable-checker
3536
# - repo: https://github.com/PyCQA/flake8
3637
# rev: 4.0.1
3738
# hooks:

discord/abc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ async def _edit(
449449
for target, perm in overwrites.items():
450450
if not isinstance(perm, PermissionOverwrite):
451451
raise InvalidArgument(
452-
f"Expected PermissionOverwrite received {perm.__class__.__name__}"
452+
"Expected PermissionOverwrite received"
453+
f" {perm.__class__.__name__}"
453454
)
454455

455456
allow, deny = perm.pair()
@@ -1516,7 +1517,8 @@ async def send(
15161517
reference = reference.to_message_reference_dict()
15171518
except AttributeError:
15181519
raise InvalidArgument(
1519-
"reference parameter must be Message, MessageReference, or PartialMessage"
1520+
"reference parameter must be Message, MessageReference, or"
1521+
" PartialMessage"
15201522
) from None
15211523

15221524
if view:

discord/activity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,10 @@ def __str__(self) -> str:
664664
return "Spotify"
665665

666666
def __repr__(self) -> str:
667-
return f"<Spotify title={self.title!r} artist={self.artist!r} track_id={self.track_id!r}>"
667+
return (
668+
"<Spotify"
669+
f" title={self.title!r} artist={self.artist!r} track_id={self.track_id!r}>"
670+
)
668671

669672
@property
670673
def title(self) -> str:
@@ -790,7 +793,8 @@ def __init__(
790793
self.emoji = emoji
791794
else:
792795
raise TypeError(
793-
f"Expected str, PartialEmoji, or None, received {type(emoji)!r} instead."
796+
"Expected str, PartialEmoji, or None, received"
797+
f" {type(emoji)!r} instead."
794798
)
795799

796800
@property

discord/bot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ def register(
505505
if kwargs.pop("_log", True):
506506
if method == "bulk":
507507
_log.debug(
508-
f"Bulk updating commands {[c['name'] for c in args[0]]} for guild {guild_id}"
508+
f"Bulk updating commands {[c['name'] for c in args[0]]} for"
509+
f" guild {guild_id}"
509510
)
510511
# TODO: Find where "cmd" is defined
511512
elif method == "upsert":
@@ -636,7 +637,8 @@ def register(
636637
)
637638
if not cmd:
638639
raise ValueError(
639-
f"Registered command {i['name']}, type {i.get('type')} not found in pending commands"
640+
f"Registered command {i['name']}, type {i.get('type')} not found in"
641+
" pending commands"
640642
)
641643
cmd.id = i["id"]
642644
self._application_commands[cmd.id] = cmd
@@ -831,7 +833,6 @@ async def process_application_commands(
831833
if guild_id is None:
832834
await self.sync_commands()
833835
else:
834-
835836
await self.sync_commands(check_guilds=[guild_id])
836837
return self._bot.dispatch("unknown_application_command", interaction)
837838

discord/channel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,10 @@ def __init__(
20612061
self._update(guild, data)
20622062

20632063
def __repr__(self) -> str:
2064-
return f"<CategoryChannel id={self.id} name={self.name!r} position={self.position} nsfw={self.nsfw}>"
2064+
return (
2065+
"<CategoryChannel"
2066+
f" id={self.id} name={self.name!r} position={self.position} nsfw={self.nsfw}>"
2067+
)
20652068

20662069
def _update(self, guild: Guild, data: CategoryChannelPayload) -> None:
20672070
# This data will always exist

discord/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ async def connect(self, *, reconnect: bool = True) -> None:
568568
aiohttp.ClientError,
569569
asyncio.TimeoutError,
570570
) as exc:
571-
572571
self.dispatch("disconnect")
573572
if not reconnect:
574573
await self.close()
@@ -1768,7 +1767,8 @@ def add_view(self, view: View, *, message_id: int | None = None) -> None:
17681767

17691768
if not view.is_persistent():
17701769
raise ValueError(
1771-
"View is not persistent. Items need to have a custom_id set and View must have no timeout"
1770+
"View is not persistent. Items need to have a custom_id set and View"
1771+
" must have no timeout"
17721772
)
17731773

17741774
self._connection.store_view(view, message_id)

discord/cog.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
143143

144144
commands = {}
145145
listeners = {}
146-
no_bot_cog = "Commands or listeners must not start with cog_ or bot_ (in method {0.__name__}.{1})"
146+
no_bot_cog = (
147+
"Commands or listeners must not start with cog_ or bot_ (in method"
148+
" {0.__name__}.{1})"
149+
)
147150

148151
new_cls = super().__new__(cls, name, bases, attrs, **kwargs)
149152

@@ -177,7 +180,8 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
177180
if isinstance(value, _filter):
178181
if is_static_method:
179182
raise TypeError(
180-
f"Command in method {base}.{elem!r} must not be staticmethod."
183+
f"Command in method {base}.{elem!r} must not be"
184+
" staticmethod."
181185
)
182186
if elem.startswith(("cog_", "bot_")):
183187
raise TypeError(no_bot_cog.format(base, elem))
@@ -187,7 +191,8 @@ def __new__(cls: type[CogMeta], *args: Any, **kwargs: Any) -> CogMeta:
187191
if hasattr(value, "add_to") and not getattr(value, "parent", None):
188192
if is_static_method:
189193
raise TypeError(
190-
f"Command in method {base}.{elem!r} must not be staticmethod."
194+
f"Command in method {base}.{elem!r} must not be"
195+
" staticmethod."
191196
)
192197
if elem.startswith(("cog_", "bot_")):
193198
raise TypeError(no_bot_cog.format(base, elem))
@@ -386,7 +391,8 @@ def listener(cls, name: str = MISSING) -> Callable[[FuncT], FuncT]:
386391

387392
if name is not MISSING and not isinstance(name, str):
388393
raise TypeError(
389-
f"Cog.listener expected str but received {name.__class__.__name__!r} instead."
394+
"Cog.listener expected str but received"
395+
f" {name.__class__.__name__!r} instead."
390396
)
391397

392398
def decorator(func: FuncT) -> FuncT:

discord/commands/context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def send_response(self) -> Callable[..., Awaitable[Interaction]]:
294294
return self.interaction.response.send_message
295295
else:
296296
raise RuntimeError(
297-
f"Interaction was already issued a response. Try using {type(self).__name__}.send_followup() instead."
297+
"Interaction was already issued a response. Try using"
298+
f" {type(self).__name__}.send_followup() instead."
298299
)
299300

300301
@property
@@ -304,7 +305,8 @@ def send_followup(self) -> Callable[..., Awaitable[WebhookMessage]]:
304305
return self.followup.send
305306
else:
306307
raise RuntimeError(
307-
f"Interaction was not yet issued a response. Try using {type(self).__name__}.respond() first."
308+
"Interaction was not yet issued a response. Try using"
309+
f" {type(self).__name__}.respond() first."
308310
)
309311

310312
@property

discord/commands/core.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ async def invoke(self, ctx: ApplicationContext) -> None:
374374
await injected(ctx)
375375

376376
async def can_run(self, ctx: ApplicationContext) -> bool:
377-
378377
if not await ctx.bot.can_run(ctx):
379378
raise CheckFailure(
380379
f"The global check functions for command {self.name} failed."
@@ -1822,7 +1821,8 @@ def validate_chat_input_name(name: Any, locale: str | None = None):
18221821
# Must meet the regex ^[-_\w\d\u0901-\u097D\u0E00-\u0E7F]{1,32}$
18231822
if locale is not None and locale not in valid_locales:
18241823
raise ValidationError(
1825-
f"Locale '{locale}' is not a valid locale, see {docs}/reference#locales for list of supported locales."
1824+
f"Locale '{locale}' is not a valid locale, see {docs}/reference#locales for"
1825+
" list of supported locales."
18261826
)
18271827
error = None
18281828
if not isinstance(name, str):
@@ -1831,8 +1831,10 @@ def validate_chat_input_name(name: Any, locale: str | None = None):
18311831
)
18321832
elif not re.match(r"^[-_\w\d\u0901-\u097D\u0E00-\u0E7F]{1,32}$", name):
18331833
error = ValidationError(
1834-
r"Command names and options must follow the regex \"^[-_\w\d\u0901-\u097D\u0E00-\u0E7F]{1,32}$\". "
1835-
f"For more information, see {docs}/interactions/application-commands#application-command-object-"
1834+
r"Command names and options must follow the regex"
1835+
r" \"^[-_\w\d\u0901-\u097D\u0E00-\u0E7F]{1,32}$\". "
1836+
"For more information, see"
1837+
f" {docs}/interactions/application-commands#application-command-object-"
18361838
f'application-command-naming. Received "{name}"'
18371839
)
18381840
elif (
@@ -1851,16 +1853,19 @@ def validate_chat_input_name(name: Any, locale: str | None = None):
18511853
def validate_chat_input_description(description: Any, locale: str | None = None):
18521854
if locale is not None and locale not in valid_locales:
18531855
raise ValidationError(
1854-
f"Locale '{locale}' is not a valid locale, see {docs}/reference#locales for list of supported locales."
1856+
f"Locale '{locale}' is not a valid locale, see {docs}/reference#locales for"
1857+
" list of supported locales."
18551858
)
18561859
error = None
18571860
if not isinstance(description, str):
18581861
error = TypeError(
1859-
f'Command and option description must be of type str. Received "{description}"'
1862+
"Command and option description must be of type str. Received"
1863+
f' "{description}"'
18601864
)
18611865
elif not 1 <= len(description) <= 100:
18621866
error = ValidationError(
1863-
f'Command and option description must be 1-100 characters long. Received "{description}"'
1867+
"Command and option description must be 1-100 characters long. Received"
1868+
f' "{description}"'
18641869
)
18651870

18661871
if error:

discord/commands/options.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,13 @@ def __init__(
278278

279279
if self.min_value is not None and not isinstance(self.min_value, minmax_types):
280280
raise TypeError(
281-
f'Expected {minmax_typehint} for min_value, got "{type(self.min_value).__name__}"'
281+
f"Expected {minmax_typehint} for min_value, got"
282+
f' "{type(self.min_value).__name__}"'
282283
)
283284
if self.max_value is not None and not isinstance(self.max_value, minmax_types):
284285
raise TypeError(
285-
f'Expected {minmax_typehint} for max_value, got "{type(self.max_value).__name__}"'
286+
f"Expected {minmax_typehint} for max_value, got"
287+
f' "{type(self.max_value).__name__}"'
286288
)
287289

288290
if self.min_length is not None:

0 commit comments

Comments
 (0)