Skip to content

Commit 44a44e9

Browse files
committed
Reformat entire project with ruff instead of black
1 parent 3ef6272 commit 44a44e9

Some content is hidden

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

88 files changed

+485
-730
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install dependencies
2828
id: install-deps
2929
run: |
30-
python -m pip install --upgrade pip setuptools wheel black==22.6 requests
30+
python -m pip install --upgrade pip setuptools wheel ruff==0.12 requests
3131
pip install -U -r requirements.txt
3232
3333
- name: Setup node.js
@@ -42,7 +42,7 @@ jobs:
4242
warnings: false
4343
no-comments: ${{ matrix.python-version != '3.x' }}
4444

45-
- name: Run black
45+
- name: Run ruff
4646
if: ${{ always() && steps.install-deps.outcome == 'success' }}
4747
run: |
48-
black --check discord examples
48+
ruff format --check discord examples

discord/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class VersionInfo(NamedTuple):
8181
major: int
8282
minor: int
8383
micro: int
84-
releaselevel: Literal["alpha", "beta", "candidate", "final"]
84+
releaselevel: Literal['alpha', 'beta', 'candidate', 'final']
8585
serial: int
8686

8787

discord/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async def setup(bot):
133133
await bot.add_cog({name}(bot))
134134
'''
135135

136-
_cog_extras = '''
136+
_cog_extras = """
137137
async def cog_load(self):
138138
# loading logic goes here
139139
pass
@@ -170,7 +170,7 @@ async def cog_after_invoke(self, ctx):
170170
# called after a command is called here
171171
pass
172172
173-
'''
173+
"""
174174

175175

176176
# certain file names and directory names are forbidden

discord/abc.py

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
PartialMessageableChannel = Union[TextChannel, VoiceChannel, StageChannel, Thread, DMChannel, PartialMessageable]
118118
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
119-
SnowflakeTime = Union["Snowflake", datetime]
119+
SnowflakeTime = Union['Snowflake', datetime]
120120

121121
class PinnedMessage(Message):
122122
pinned_at: datetime
@@ -140,7 +140,7 @@ def __init__(self, iterator: AsyncIterator[PinnedMessage]) -> None:
140140

141141
def __await__(self) -> Generator[Any, None, List[PinnedMessage]]:
142142
warnings.warn(
143-
"`await <channel>.pins()` is deprecated; use `async for message in <channel>.pins()` instead.",
143+
'`await <channel>.pins()` is deprecated; use `async for message in <channel>.pins()` instead.',
144144
DeprecationWarning,
145145
stacklevel=2,
146146
)
@@ -423,8 +423,7 @@ class GuildChannel:
423423

424424
if TYPE_CHECKING:
425425

426-
def __init__(self, *, state: ConnectionState, guild: Guild, data: GuildChannelPayload):
427-
...
426+
def __init__(self, *, state: ConnectionState, guild: Guild, data: GuildChannelPayload): ...
428427

429428
def __str__(self) -> str:
430429
return self.name
@@ -794,7 +793,6 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
794793

795794
default = self.guild.default_role
796795
if default is None:
797-
798796
if self._state.self_id == obj.id:
799797
return Permissions._user_installed_permissions(in_guild=True)
800798
else:
@@ -907,8 +905,7 @@ async def set_permissions(
907905
*,
908906
overwrite: Optional[Union[PermissionOverwrite, _Undefined]] = ...,
909907
reason: Optional[str] = ...,
910-
) -> None:
911-
...
908+
) -> None: ...
912909

913910
@overload
914911
async def set_permissions(
@@ -917,8 +914,7 @@ async def set_permissions(
917914
*,
918915
reason: Optional[str] = ...,
919916
**permissions: Unpack[_PermissionOverwriteKwargs],
920-
) -> None:
921-
...
917+
) -> None: ...
922918

923919
async def set_permissions(
924920
self,
@@ -1109,8 +1105,7 @@ async def move(
11091105
category: Optional[Snowflake] = MISSING,
11101106
sync_permissions: bool = MISSING,
11111107
reason: Optional[str] = MISSING,
1112-
) -> None:
1113-
...
1108+
) -> None: ...
11141109

11151110
@overload
11161111
async def move(
@@ -1121,8 +1116,7 @@ async def move(
11211116
category: Optional[Snowflake] = MISSING,
11221117
sync_permissions: bool = MISSING,
11231118
reason: str = MISSING,
1124-
) -> None:
1125-
...
1119+
) -> None: ...
11261120

11271121
@overload
11281122
async def move(
@@ -1133,8 +1127,7 @@ async def move(
11331127
category: Optional[Snowflake] = MISSING,
11341128
sync_permissions: bool = MISSING,
11351129
reason: str = MISSING,
1136-
) -> None:
1137-
...
1130+
) -> None: ...
11381131

11391132
@overload
11401133
async def move(
@@ -1145,8 +1138,7 @@ async def move(
11451138
category: Optional[Snowflake] = MISSING,
11461139
sync_permissions: bool = MISSING,
11471140
reason: str = MISSING,
1148-
) -> None:
1149-
...
1141+
) -> None: ...
11501142

11511143
async def move(self, **kwargs: Any) -> None:
11521144
"""|coro|
@@ -1428,8 +1420,7 @@ async def send(
14281420
view: LayoutView,
14291421
suppress_embeds: bool = ...,
14301422
silent: bool = ...,
1431-
) -> Message:
1432-
...
1423+
) -> Message: ...
14331424

14341425
@overload
14351426
async def send(
@@ -1444,8 +1435,7 @@ async def send(
14441435
view: LayoutView,
14451436
suppress_embeds: bool = ...,
14461437
silent: bool = ...,
1447-
) -> Message:
1448-
...
1438+
) -> Message: ...
14491439

14501440
@overload
14511441
async def send(
@@ -1465,8 +1455,7 @@ async def send(
14651455
suppress_embeds: bool = ...,
14661456
silent: bool = ...,
14671457
poll: Poll = ...,
1468-
) -> Message:
1469-
...
1458+
) -> Message: ...
14701459

14711460
@overload
14721461
async def send(
@@ -1486,8 +1475,7 @@ async def send(
14861475
suppress_embeds: bool = ...,
14871476
silent: bool = ...,
14881477
poll: Poll = ...,
1489-
) -> Message:
1490-
...
1478+
) -> Message: ...
14911479

14921480
@overload
14931481
async def send(
@@ -1507,8 +1495,7 @@ async def send(
15071495
suppress_embeds: bool = ...,
15081496
silent: bool = ...,
15091497
poll: Poll = ...,
1510-
) -> Message:
1511-
...
1498+
) -> Message: ...
15121499

15131500
@overload
15141501
async def send(
@@ -1528,8 +1515,7 @@ async def send(
15281515
suppress_embeds: bool = ...,
15291516
silent: bool = ...,
15301517
poll: Poll = ...,
1531-
) -> Message:
1532-
...
1518+
) -> Message: ...
15331519

15341520
async def send(
15351521
self,
@@ -2029,7 +2015,7 @@ async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Op
20292015
if limit is None:
20302016
raise ValueError('history does not support around with limit=None')
20312017
if limit > 101:
2032-
raise ValueError("history max limit 101 when specifying around parameter")
2018+
raise ValueError('history max limit 101 when specifying around parameter')
20332019

20342020
# Strange Discord quirk
20352021
limit = 100 if limit == 101 else limit

discord/activity.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,11 @@ def __repr__(self) -> str:
861861

862862

863863
@overload
864-
def create_activity(data: ActivityPayload, state: ConnectionState) -> ActivityTypes:
865-
...
864+
def create_activity(data: ActivityPayload, state: ConnectionState) -> ActivityTypes: ...
866865

867866

868867
@overload
869-
def create_activity(data: None, state: ConnectionState) -> None:
870-
...
868+
def create_activity(data: None, state: ConnectionState) -> None: ...
871869

872870

873871
def create_activity(data: Optional[ActivityPayload], state: ConnectionState) -> Optional[ActivityTypes]:

discord/app_commands/checks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async def test(interaction: discord.Interaction):
327327

328328
invalid = perms.keys() - Permissions.VALID_FLAGS.keys()
329329
if invalid:
330-
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
330+
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
331331

332332
def predicate(interaction: Interaction) -> bool:
333333
permissions = interaction.permissions
@@ -354,7 +354,7 @@ def bot_has_permissions(**perms: Unpack[_PermissionsKwargs]) -> Callable[[T], T]
354354

355355
invalid = set(perms) - set(Permissions.VALID_FLAGS)
356356
if invalid:
357-
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
357+
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
358358

359359
def predicate(interaction: Interaction) -> bool:
360360
permissions = interaction.app_permissions
@@ -371,7 +371,6 @@ def predicate(interaction: Interaction) -> bool:
371371
def _create_cooldown_decorator(
372372
key: CooldownFunction[Hashable], factory: CooldownFunction[Optional[Cooldown]]
373373
) -> Callable[[T], T]:
374-
375374
mapping: Dict[Any, Cooldown] = {}
376375

377376
async def get_bucket(

discord/app_commands/commands.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def validate_context_menu_name(name: str) -> str:
219219

220220

221221
def validate_auto_complete_callback(
222-
callback: AutocompleteCallback[GroupT, ChoiceT]
222+
callback: AutocompleteCallback[GroupT, ChoiceT],
223223
) -> AutocompleteCallback[GroupT, ChoiceT]:
224224
# This function needs to ensure the following is true:
225225
# If self.foo is passed then don't pass command.binding to the callback
@@ -1491,9 +1491,9 @@ class shortened to 100 characters.
14911491
__discord_app_commands_installation_types__: Optional[AppInstallationType] = MISSING
14921492
__discord_app_commands_default_permissions__: Optional[Permissions] = MISSING
14931493
__discord_app_commands_has_module__: bool = False
1494-
__discord_app_commands_error_handler__: Optional[
1495-
Callable[[Interaction, AppCommandError], Coroutine[Any, Any, None]]
1496-
] = None
1494+
__discord_app_commands_error_handler__: Optional[Callable[[Interaction, AppCommandError], Coroutine[Any, Any, None]]] = (
1495+
None
1496+
)
14971497

14981498
def __init_subclass__(
14991499
cls,
@@ -2484,13 +2484,11 @@ def decorator(func: CheckInputParameter) -> CheckInputParameter:
24842484

24852485

24862486
@overload
2487-
def guild_only(func: None = ...) -> Callable[[T], T]:
2488-
...
2487+
def guild_only(func: None = ...) -> Callable[[T], T]: ...
24892488

24902489

24912490
@overload
2492-
def guild_only(func: T) -> T:
2493-
...
2491+
def guild_only(func: T) -> T: ...
24942492

24952493

24962494
def guild_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:
@@ -2541,13 +2539,11 @@ def inner(f: T) -> T:
25412539

25422540

25432541
@overload
2544-
def private_channel_only(func: None = ...) -> Callable[[T], T]:
2545-
...
2542+
def private_channel_only(func: None = ...) -> Callable[[T], T]: ...
25462543

25472544

25482545
@overload
2549-
def private_channel_only(func: T) -> T:
2550-
...
2546+
def private_channel_only(func: T) -> T: ...
25512547

25522548

25532549
def private_channel_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:
@@ -2598,13 +2594,11 @@ def inner(f: T) -> T:
25982594

25992595

26002596
@overload
2601-
def dm_only(func: None = ...) -> Callable[[T], T]:
2602-
...
2597+
def dm_only(func: None = ...) -> Callable[[T], T]: ...
26032598

26042599

26052600
@overload
2606-
def dm_only(func: T) -> T:
2607-
...
2601+
def dm_only(func: T) -> T: ...
26082602

26092603

26102604
def dm_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:
@@ -2697,13 +2691,11 @@ def inner(f: T) -> T:
26972691

26982692

26992693
@overload
2700-
def guild_install(func: None = ...) -> Callable[[T], T]:
2701-
...
2694+
def guild_install(func: None = ...) -> Callable[[T], T]: ...
27022695

27032696

27042697
@overload
2705-
def guild_install(func: T) -> T:
2706-
...
2698+
def guild_install(func: T) -> T: ...
27072699

27082700

27092701
def guild_install(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:
@@ -2748,13 +2740,11 @@ def inner(f: T) -> T:
27482740

27492741

27502742
@overload
2751-
def user_install(func: None = ...) -> Callable[[T], T]:
2752-
...
2743+
def user_install(func: None = ...) -> Callable[[T], T]: ...
27532744

27542745

27552746
@overload
2756-
def user_install(func: T) -> T:
2757-
...
2747+
def user_install(func: T) -> T: ...
27582748

27592749

27602750
def user_install(func: Optional[T] = None) -> Union[T, Callable[[T], T]]:

discord/app_commands/namespace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _get_resolved_items(cls, interaction: Interaction, resolved: ResolvedData) -
181181
guild_id = interaction.guild_id
182182
guild = interaction.guild
183183
type = AppCommandOptionType.user.value
184-
for (user_id, user_data) in resolved.get('users', {}).items():
184+
for user_id, user_data in resolved.get('users', {}).items():
185185
try:
186186
member_data = members[user_id]
187187
except KeyError:
@@ -203,7 +203,7 @@ def _get_resolved_items(cls, interaction: Interaction, resolved: ResolvedData) -
203203
)
204204

205205
type = AppCommandOptionType.channel.value
206-
for (channel_id, channel_data) in resolved.get('channels', {}).items():
206+
for channel_id, channel_data in resolved.get('channels', {}).items():
207207
key = ResolveKey(id=channel_id, type=type)
208208
if channel_data['type'] in (10, 11, 12):
209209
# The guild ID can't be none in this case
@@ -220,7 +220,7 @@ def _get_resolved_items(cls, interaction: Interaction, resolved: ResolvedData) -
220220
}
221221
)
222222

223-
for (message_id, message_data) in resolved.get('messages', {}).items():
223+
for message_id, message_data in resolved.get('messages', {}).items():
224224
channel_id = int(message_data['channel_id'])
225225
if guild is None:
226226
channel = PartialMessageable(state=state, guild_id=guild_id, id=channel_id)

0 commit comments

Comments
 (0)