Skip to content

Commit 75a6e77

Browse files
shiftinvEnegg
andauthored
chore: rename __repr_info__ -> __repr_attributes__, enable RUF005 (DisnakeDev#1320)
Signed-off-by: vi <8530778+shiftinv@users.noreply.github.com> Co-authored-by: Eneg <42005170+Enegg@users.noreply.github.com>
1 parent 911171b commit 75a6e77

File tree

11 files changed

+57
-35
lines changed

11 files changed

+57
-35
lines changed

disnake/app_commands.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class ApplicationCommand(ABC): # noqa: B024 # this will get refactored eventua
506506
.. versionadded:: 2.10
507507
"""
508508

509-
__repr_info__: ClassVar[Tuple[str, ...]] = (
509+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
510510
"type",
511511
"name",
512512
"default_member_permissions",
@@ -614,7 +614,7 @@ def dm_permission(self, value: bool) -> None:
614614
self._dm_permission = value
615615

616616
def __repr__(self) -> str:
617-
attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_info__)
617+
attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_attributes__)
618618
return f"<{type(self).__name__} {attrs}>"
619619

620620
def __str__(self) -> str:
@@ -726,7 +726,7 @@ def localize(self, store: LocalizationProtocol) -> None:
726726

727727

728728
class _APIApplicationCommandMixin:
729-
__repr_info__ = ("id",)
729+
__repr_attributes__: ClassVar[Tuple[str, ...]] = ("id",)
730730

731731
def _update_common(self, data: ApplicationCommandPayload) -> None:
732732
if not isinstance(self, ApplicationCommand):
@@ -776,7 +776,9 @@ class UserCommand(ApplicationCommand):
776776
.. versionadded:: 2.10
777777
"""
778778

779-
__repr_info__ = tuple(n for n in ApplicationCommand.__repr_info__ if n != "type")
779+
__repr_attributes__: ClassVar[Tuple[str, ...]] = tuple(
780+
n for n in ApplicationCommand.__repr_attributes__ if n != "type"
781+
)
780782

781783
def __init__(
782784
self,
@@ -840,7 +842,10 @@ class APIUserCommand(UserCommand, _APIApplicationCommandMixin):
840842
Autoincrementing version identifier updated during substantial record changes.
841843
"""
842844

843-
__repr_info__ = UserCommand.__repr_info__ + _APIApplicationCommandMixin.__repr_info__
845+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
846+
*UserCommand.__repr_attributes__,
847+
*_APIApplicationCommandMixin.__repr_attributes__,
848+
)
844849

845850
@classmethod
846851
def from_dict(cls, data: ApplicationCommandPayload) -> Self:
@@ -899,7 +904,9 @@ class MessageCommand(ApplicationCommand):
899904
.. versionadded:: 2.10
900905
"""
901906

902-
__repr_info__ = tuple(n for n in ApplicationCommand.__repr_info__ if n != "type")
907+
__repr_attributes__: ClassVar[Tuple[str, ...]] = tuple(
908+
n for n in ApplicationCommand.__repr_attributes__ if n != "type"
909+
)
903910

904911
def __init__(
905912
self,
@@ -963,7 +970,10 @@ class APIMessageCommand(MessageCommand, _APIApplicationCommandMixin):
963970
Autoincrementing version identifier updated during substantial record changes.
964971
"""
965972

966-
__repr_info__ = MessageCommand.__repr_info__ + _APIApplicationCommandMixin.__repr_info__
973+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
974+
*MessageCommand.__repr_attributes__,
975+
*_APIApplicationCommandMixin.__repr_attributes__,
976+
)
967977

968978
@classmethod
969979
def from_dict(cls, data: ApplicationCommandPayload) -> Self:
@@ -1032,7 +1042,8 @@ class SlashCommand(ApplicationCommand):
10321042
The list of options the slash command has.
10331043
"""
10341044

1035-
__repr_info__ = tuple(n for n in ApplicationCommand.__repr_info__ if n != "type") + (
1045+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
1046+
*tuple(n for n in ApplicationCommand.__repr_attributes__ if n != "type"),
10361047
"description",
10371048
"options",
10381049
)
@@ -1179,7 +1190,10 @@ class APISlashCommand(SlashCommand, _APIApplicationCommandMixin):
11791190
Autoincrementing version identifier updated during substantial record changes.
11801191
"""
11811192

1182-
__repr_info__ = SlashCommand.__repr_info__ + _APIApplicationCommandMixin.__repr_info__
1193+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
1194+
*SlashCommand.__repr_attributes__,
1195+
*_APIApplicationCommandMixin.__repr_attributes__,
1196+
)
11831197

11841198
@classmethod
11851199
def from_dict(cls, data: ApplicationCommandPayload) -> Self:

disnake/components.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Component:
185185

186186
__slots__: Tuple[str, ...] = ("type", "id")
187187

188-
__repr_info__: ClassVar[Tuple[str, ...]]
188+
__repr_attributes__: ClassVar[Tuple[str, ...]]
189189

190190
# subclasses are expected to overwrite this if they're only usable with `MessageFlags.is_components_v2`
191191
is_v2: ClassVar[bool] = False
@@ -194,7 +194,7 @@ class Component:
194194
id: int
195195

196196
def __repr__(self) -> str:
197-
attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_info__)
197+
attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_attributes__)
198198
return f"<{self.__class__.__name__} {attrs}>"
199199

200200
@classmethod
@@ -236,7 +236,7 @@ class ActionRow(Component, Generic[ActionRowChildComponentT]):
236236

237237
__slots__: Tuple[str, ...] = ("children",)
238238

239-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
239+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
240240

241241
def __init__(self, data: ActionRowPayload) -> None:
242242
self.type: Literal[ComponentType.action_row] = ComponentType.action_row
@@ -303,7 +303,7 @@ class Button(Component):
303303
"sku_id",
304304
)
305305

306-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
306+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
307307

308308
def __init__(self, data: ButtonComponentPayload) -> None:
309309
self.type: Literal[ComponentType.button] = ComponentType.button
@@ -404,7 +404,9 @@ class BaseSelectMenu(Component):
404404
)
405405

406406
# FIXME: this isn't pretty; we should decouple __repr__ from slots
407-
__repr_info__: ClassVar[Tuple[str, ...]] = tuple(s for s in __slots__ if s != "default_values")
407+
__repr_attributes__: ClassVar[Tuple[str, ...]] = tuple(
408+
s for s in __slots__ if s != "default_values"
409+
)
408410

409411
# n.b: ideally this would be `BaseSelectMenuPayload`,
410412
# but pyright made TypedDict keys invariant and doesn't
@@ -480,7 +482,10 @@ class StringSelectMenu(BaseSelectMenu):
480482

481483
__slots__: Tuple[str, ...] = ("options",)
482484

483-
__repr_info__: ClassVar[Tuple[str, ...]] = BaseSelectMenu.__repr_info__ + __slots__
485+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
486+
*BaseSelectMenu.__repr_attributes__,
487+
*__slots__,
488+
)
484489
type: Literal[ComponentType.string_select]
485490

486491
def __init__(self, data: StringSelectMenuPayload) -> None:
@@ -677,7 +682,10 @@ class ChannelSelectMenu(BaseSelectMenu):
677682

678683
__slots__: Tuple[str, ...] = ("channel_types",)
679684

680-
__repr_info__: ClassVar[Tuple[str, ...]] = BaseSelectMenu.__repr_info__ + __slots__
685+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
686+
*BaseSelectMenu.__repr_attributes__,
687+
*__slots__,
688+
)
681689
type: Literal[ComponentType.channel_select]
682690

683691
def __init__(self, data: ChannelSelectMenuPayload) -> None:
@@ -884,7 +892,7 @@ class TextInput(Component):
884892
"min_length",
885893
)
886894

887-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
895+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
888896

889897
def __init__(self, data: TextInputPayload) -> None:
890898
self.type: Literal[ComponentType.text_input] = ComponentType.text_input
@@ -953,7 +961,7 @@ class Section(Component):
953961

954962
__slots__: Tuple[str, ...] = ("children", "accessory")
955963

956-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
964+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
957965

958966
is_v2 = True
959967

@@ -1000,7 +1008,7 @@ class TextDisplay(Component):
10001008

10011009
__slots__: Tuple[str, ...] = ("content",)
10021010

1003-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1011+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
10041012

10051013
is_v2 = True
10061014

@@ -1112,7 +1120,7 @@ class Thumbnail(Component):
11121120
"spoiler",
11131121
)
11141122

1115-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1123+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
11161124

11171125
is_v2 = True
11181126

@@ -1163,7 +1171,7 @@ class MediaGallery(Component):
11631171

11641172
__slots__: Tuple[str, ...] = ("items",)
11651173

1166-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1174+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
11671175

11681176
is_v2 = True
11691177

@@ -1271,7 +1279,7 @@ class FileComponent(Component):
12711279

12721280
__slots__: Tuple[str, ...] = ("file", "spoiler", "name", "size")
12731281

1274-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1282+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
12751283

12761284
is_v2 = True
12771285

@@ -1322,7 +1330,7 @@ class Separator(Component):
13221330

13231331
__slots__: Tuple[str, ...] = ("divider", "spacing")
13241332

1325-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1333+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
13261334

13271335
is_v2 = True
13281336

@@ -1375,7 +1383,7 @@ class Container(Component):
13751383
"spoiler",
13761384
)
13771385

1378-
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
1386+
__repr_attributes__: ClassVar[Tuple[str, ...]] = __slots__
13791387

13801388
is_v2 = True
13811389

disnake/ext/commands/ctx_menus_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async def __call__(
136136
**kwargs: Any,
137137
) -> None:
138138
# the target may just not be passed in
139-
args = (target or interaction.target,) + args
139+
args = (target or interaction.target, *args)
140140
if self.cog is not None:
141141
await safe_call(self.callback, self.cog, interaction, *args, **kwargs)
142142
else:
@@ -248,7 +248,7 @@ async def __call__(
248248
**kwargs: Any,
249249
) -> None:
250250
# the target may just not be passed in
251-
args = (target or interaction.target,) + args
251+
args = (target or interaction.target, *args)
252252
if self.cog is not None:
253253
await safe_call(self.callback, self.cog, interaction, *args, **kwargs)
254254
else:

disnake/ext/commands/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def __class_getitem__(cls, params: Tuple[Any, ...]) -> Self:
292292
)
293293

294294
# infer type from min/max values
295-
params = (cls._infer_type(params),) + params
295+
params = (cls._infer_type(params), *params)
296296

297297
if len(params) != 3:
298298
raise TypeError(

disnake/interactions/application_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _get_chain_and_kwargs(
282282
for option in self.options:
283283
if option.value is None:
284284
# Extend the chain and collect kwargs in the nesting
285-
return option._get_chain_and_kwargs(chain + (option.name,))
285+
return option._get_chain_and_kwargs((*chain, option.name))
286286
return chain, {o.name: o.value for o in self.options}
287287
return chain, {}
288288

@@ -367,7 +367,7 @@ def _get_chain_and_kwargs(
367367
for option in self.options:
368368
if option.value is None:
369369
# Extend the chain and collect kwargs in the nesting
370-
return option._get_chain_and_kwargs(chain + (option.name,))
370+
return option._get_chain_and_kwargs((*chain, option.name))
371371
return chain, {o.name: o.value for o in self.options}
372372
return chain, {}
373373

disnake/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ def parse_guild_soundboard_sound_create(self, data: gateway.GuildSoundboardSound
20352035
self._handle_soundboard_update(
20362036
guild,
20372037
# append new sound
2038-
guild.soundboard_sounds + (sound,),
2038+
(*guild.soundboard_sounds, sound),
20392039
)
20402040

20412041
def parse_guild_soundboard_sound_update(self, data: gateway.GuildSoundboardSoundUpdate) -> None:

disnake/ui/select/channel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class ChannelSelect(BaseSelect[ChannelSelectMenu, "AnyChannel", V_co]):
9090
A list of channels that have been selected by the user.
9191
"""
9292

93-
__repr_attributes__: ClassVar[Tuple[str, ...]] = BaseSelect.__repr_attributes__ + (
93+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
94+
*BaseSelect.__repr_attributes__,
9495
"channel_types",
9596
)
9697

disnake/ui/select/string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class StringSelect(BaseSelect[StringSelectMenu, str, V_co]):
105105
A list of values that have been selected by the user.
106106
"""
107107

108-
__repr_attributes__: ClassVar[Tuple[str, ...]] = BaseSelect.__repr_attributes__ + ("options",)
108+
__repr_attributes__: ClassVar[Tuple[str, ...]] = (*BaseSelect.__repr_attributes__, "options")
109109

110110
# In practice this should never be used by anything, might as well have it anyway though.
111111
_default_value_type_map: ClassVar[

disnake/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ def flatten_literal_params(parameters: Iterable[Any]) -> Tuple[Any, ...]:
11351135

11361136
def normalise_optional_params(parameters: Iterable[Any]) -> Tuple[Any, ...]:
11371137
none_cls = type(None)
1138-
return tuple(p for p in parameters if p is not none_cls) + (none_cls,)
1138+
return (*tuple(p for p in parameters if p is not none_cls), none_cls)
11391139

11401140

11411141
def _resolve_typealiastype(

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def codemod(session: nox.Session) -> None:
168168
session.run_always("pdm", "install", "-dG", "codemod", external=True)
169169

170170
base_command = ["python", "-m", "libcst.tool"]
171-
base_command_codemod = base_command + ["codemod"]
171+
base_command_codemod = [*base_command, "codemod"]
172172
if not session.interactive:
173173
base_command_codemod += ["--hide-progress"]
174174

0 commit comments

Comments
 (0)