Skip to content

Commit cdc56a5

Browse files
committed
🚨 Fix ruff warnings and format code
1 parent c72b628 commit cdc56a5

26 files changed

+81
-223
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ ci:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v5.0.0
7+
rev: v6.0.0
88
hooks:
99
- id: trailing-whitespace
1010
exclude: \.(po|pot|yml|yaml)$
1111
- id: end-of-file-fixer
1212
exclude: \.(po|pot|yml|yaml)$
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.11.9
14+
rev: v0.12.9
1515
hooks:
1616
- id: ruff
1717
args: [ --fix ]

discord/abc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,7 @@ async def send(
15471547
components = view.to_components()
15481548
if view.is_components_v2():
15491549
if embeds or content:
1550-
raise TypeError(
1551-
"cannot send embeds or content with a view using v2 component logic"
1552-
)
1550+
raise TypeError("cannot send embeds or content with a view using v2 component logic")
15531551
flags.is_components_v2 = True
15541552
else:
15551553
components = None

discord/channel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,7 @@ async def create_thread(
12691269
components = view.to_components()
12701270
if view.is_components_v2():
12711271
if embeds or content:
1272-
raise TypeError(
1273-
"cannot send embeds or content with a view using v2 component logic"
1274-
)
1272+
raise TypeError("cannot send embeds or content with a view using v2 component logic")
12751273
flags.is_components_v2 = True
12761274
else:
12771275
components = None

discord/client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ async def on_error(self, event_method: str, *args: Any, **kwargs: Any) -> None:
540540
print(f"Ignoring exception in {event_method}", file=sys.stderr)
541541
traceback.print_exc()
542542

543-
async def on_view_error(
544-
self, error: Exception, item: Item, interaction: Interaction
545-
) -> None:
543+
async def on_view_error(self, error: Exception, item: Item, interaction: Interaction) -> None:
546544
"""|coro|
547545
548546
The default view error handler provided by the client.
@@ -554,9 +552,7 @@ async def on_view_error(
554552
f"Ignoring exception in view {interaction.view} for item {item}:",
555553
file=sys.stderr,
556554
)
557-
traceback.print_exception(
558-
error.__class__, error, error.__traceback__, file=sys.stderr
559-
)
555+
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
560556

561557
async def on_modal_error(self, error: Exception, interaction: Interaction) -> None:
562558
"""|coro|
@@ -568,9 +564,7 @@ async def on_modal_error(self, error: Exception, interaction: Interaction) -> No
568564
"""
569565

570566
print(f"Ignoring exception in modal {interaction.modal}:", file=sys.stderr)
571-
traceback.print_exception(
572-
error.__class__, error, error.__traceback__, file=sys.stderr
573-
)
567+
traceback.print_exception(error.__class__, error, error.__traceback__, file=sys.stderr)
574568

575569
# hooks
576570

discord/collectibles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, data: NameplatePayload, state: "ConnectionState") -> None:
5050
self.palette: str = data["palette"]
5151
self._label: str = data["label"]
5252
self._asset: str = data["asset"]
53-
self._state: "ConnectionState" = state
53+
self._state: ConnectionState = state
5454

5555
def __repr__(self) -> str:
5656
return f"<Nameplate sku_id={self.sku_id} palette={self.palette}>"

discord/commands/core.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,21 +782,15 @@ def _parse_options(self, params, *, check_params: bool = True) -> list[Option]:
782782
if self._is_typing_literal(option):
783783
literal_values = get_args(option)
784784
if not all(isinstance(v, (str, int, float)) for v in literal_values):
785-
raise TypeError(
786-
"Literal values for choices must be str, int, or float."
787-
)
785+
raise TypeError("Literal values for choices must be str, int, or float.")
788786

789787
value_type = type(literal_values[0])
790788
if not all(isinstance(v, value_type) for v in literal_values):
791-
raise TypeError(
792-
"All Literal values for choices must be of the same type."
793-
)
789+
raise TypeError("All Literal values for choices must be of the same type.")
794790

795791
option = Option(
796792
value_type,
797-
choices=[
798-
OptionChoice(name=str(v), value=v) for v in literal_values
799-
],
793+
choices=[OptionChoice(name=str(v), value=v) for v in literal_values],
800794
)
801795

802796
if self._is_typing_annotated(option):

discord/components.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ class ActionRow(Component):
165165
def __init__(self, data: ComponentPayload):
166166
self.type: ComponentType = try_enum(ComponentType, data["type"])
167167
self.id: int = data.get("id")
168-
self.children: list[Component] = [
169-
_component_factory(d) for d in data.get("components", [])
170-
]
168+
self.children: list[Component] = [_component_factory(d) for d in data.get("components", [])]
171169

172170
@property
173171
def width(self):
@@ -189,9 +187,7 @@ def walk_components(self) -> Iterator[Component]:
189187

190188
@classmethod
191189
def with_components(cls, *components, id=None):
192-
return cls._raw_construct(
193-
type=ComponentType.action_row, id=id, children=[c for c in components]
194-
)
190+
return cls._raw_construct(type=ComponentType.action_row, id=id, children=[c for c in components])
195191

196192

197193
class InputText(Component):
@@ -592,9 +588,7 @@ class Section(Component):
592588
def __init__(self, data: SectionComponentPayload, state=None):
593589
self.type: ComponentType = try_enum(ComponentType, data["type"])
594590
self.id: int = data.get("id")
595-
self.components: list[Component] = [
596-
_component_factory(d, state=state) for d in data.get("components", [])
597-
]
591+
self.components: list[Component] = [_component_factory(d, state=state) for d in data.get("components", [])]
598592
self.accessory: Component | None = None
599593
if _accessory := data.get("accessory"):
600594
self.accessory = _component_factory(_accessory, state=state)
@@ -665,9 +659,7 @@ class UnfurledMediaItem(AssetMixin):
665659
def __init__(self, url: str):
666660
self._state = None
667661
self._url: str = url
668-
self._static_url: str | None = (
669-
url if url and url.startswith("attachment://") else None
670-
)
662+
self._static_url: str | None = url if url and url.startswith("attachment://") else None
671663
self.proxy_url: str | None = None
672664
self.height: int | None = None
673665
self.width: int | None = None
@@ -676,9 +668,7 @@ def __init__(self, url: str):
676668
self.attachment_id: int | None = None
677669

678670
def __repr__(self) -> str:
679-
return (
680-
f"<UnfurledMediaItem url={self.url!r} attachment_id={self.attachment_id}>"
681-
)
671+
return f"<UnfurledMediaItem url={self.url!r} attachment_id={self.attachment_id}>"
682672

683673
def __str__(self) -> str:
684674
return self.url or self.__repr__()
@@ -691,13 +681,10 @@ def url(self) -> str:
691681
@url.setter
692682
def url(self, value: str) -> None:
693683
self._url = value
694-
self._static_url = (
695-
value if value and value.startswith("attachment://") else None
696-
)
684+
self._static_url = value if value and value.startswith("attachment://") else None
697685

698686
@classmethod
699687
def from_dict(cls, data: UnfurledMediaItemPayload, state=None) -> UnfurledMediaItem:
700-
701688
r = cls(data.get("url"))
702689
r.proxy_url = data.get("proxy_url")
703690
r.height = data.get("height")
@@ -747,9 +734,7 @@ class Thumbnail(Component):
747734
def __init__(self, data: ThumbnailComponentPayload, state=None):
748735
self.type: ComponentType = try_enum(ComponentType, data["type"])
749736
self.id: int = data.get("id")
750-
self.media: UnfurledMediaItem = (
751-
umi := data.get("media")
752-
) and UnfurledMediaItem.from_dict(umi, state=state)
737+
self.media: UnfurledMediaItem = (umi := data.get("media")) and UnfurledMediaItem.from_dict(umi, state=state)
753738
self.description: str | None = data.get("description")
754739
self.spoiler: bool | None = data.get("spoiler")
755740

@@ -800,9 +785,7 @@ def is_dispatchable(self) -> bool:
800785

801786
@classmethod
802787
def from_dict(cls, data: MediaGalleryItemPayload, state=None) -> MediaGalleryItem:
803-
media = (umi := data.get("media")) and UnfurledMediaItem.from_dict(
804-
umi, state=state
805-
)
788+
media = (umi := data.get("media")) and UnfurledMediaItem.from_dict(umi, state=state)
806789
description = data.get("description")
807790
spoiler = data.get("spoiler", False)
808791

@@ -851,9 +834,7 @@ class MediaGallery(Component):
851834
def __init__(self, data: MediaGalleryComponentPayload, state=None):
852835
self.type: ComponentType = try_enum(ComponentType, data["type"])
853836
self.id: int = data.get("id")
854-
self.items: list[MediaGalleryItem] = [
855-
MediaGalleryItem.from_dict(d, state=state) for d in data.get("items", [])
856-
]
837+
self.items: list[MediaGalleryItem] = [MediaGalleryItem.from_dict(d, state=state) for d in data.get("items", [])]
857838

858839
def to_dict(self) -> MediaGalleryComponentPayload:
859840
return {
@@ -903,9 +884,7 @@ def __init__(self, data: FileComponentPayload, state=None):
903884
self.id: int = data.get("id")
904885
self.name: str = data.get("name")
905886
self.size: int = data.get("size")
906-
self.file: UnfurledMediaItem = UnfurledMediaItem.from_dict(
907-
data.get("file", {}), state=state
908-
)
887+
self.file: UnfurledMediaItem = UnfurledMediaItem.from_dict(data.get("file", {}), state=state)
909888
self.spoiler: bool | None = data.get("spoiler")
910889

911890
def to_dict(self) -> FileComponentPayload:
@@ -948,9 +927,7 @@ def __init__(self, data: SeparatorComponentPayload):
948927
self.type: ComponentType = try_enum(ComponentType, data["type"])
949928
self.id: int = data.get("id")
950929
self.divider: bool = data.get("divider")
951-
self.spacing: SeparatorSpacingSize = try_enum(
952-
SeparatorSpacingSize, data.get("spacing", 1)
953-
)
930+
self.spacing: SeparatorSpacingSize = try_enum(SeparatorSpacingSize, data.get("spacing", 1))
954931

955932
def to_dict(self) -> SeparatorComponentPayload:
956933
return {
@@ -1008,9 +985,7 @@ def __init__(self, data: ContainerComponentPayload, state=None):
1008985
c
1009986
) # at this point, not adding alternative spelling
1010987
self.spoiler: bool | None = data.get("spoiler")
1011-
self.components: list[Component] = [
1012-
_component_factory(d, state=state) for d in data.get("components", [])
1013-
]
988+
self.components: list[Component] = [_component_factory(d, state=state) for d in data.get("components", [])]
1014989

1015990
def to_dict(self) -> ContainerComponentPayload:
1016991
payload = {

discord/ext/commands/converter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,7 @@ def get_converter(param: inspect.Parameter) -> Any:
10501050

10511051

10521052
def is_generic_type(tp: Any, *, _GenericAlias: type = _GenericAlias) -> bool:
1053-
return (
1054-
isinstance(tp, type)
1055-
and issubclass(tp, Generic)
1056-
or isinstance(tp, _GenericAlias)
1057-
) # type: ignore
1053+
return isinstance(tp, type) and issubclass(tp, Generic) or isinstance(tp, _GenericAlias) # type: ignore
10581054

10591055

10601056
CONVERTER_MAPPING: dict[type[Any], Any] = {

discord/ext/pages/pagination.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def __init__(
149149
**kwargs,
150150
):
151151
if content is None and embeds is None and custom_view is None:
152-
raise discord.InvalidArgument(
153-
"A page must at least have content, embeds, or custom_view set."
154-
)
152+
raise discord.InvalidArgument("A page must at least have content, embeds, or custom_view set.")
155153
self._content = content
156154
self._embeds = embeds or []
157155
self._custom_view = custom_view
@@ -562,11 +560,9 @@ async def disable(
562560
"""
563561
page = self.get_page_content(page)
564562
for item in self.walk_children():
565-
if (
566-
include_custom
567-
or not self.custom_view
568-
or item not in self.custom_view.children
569-
) and hasattr(item, "disabled"):
563+
if (include_custom or not self.custom_view or item not in self.custom_view.children) and hasattr(
564+
item, "disabled"
565+
):
570566
item.disabled = True
571567
if page:
572568
await self.message.edit(

discord/guild.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ async def templates(self) -> list[Template]:
22602260
Forbidden
22612261
You don't have permissions to get the templates.
22622262
"""
2263-
from .template import Template
2263+
from .template import Template # noqa: PLC0415
22642264

22652265
data = await self._state.http.guild_templates(self.id)
22662266
return [Template(data=d, state=self._state) for d in data]
@@ -2283,7 +2283,7 @@ async def webhooks(self) -> list[Webhook]:
22832283
You don't have permissions to get the webhooks.
22842284
"""
22852285

2286-
from .webhook import Webhook
2286+
from .webhook import Webhook # noqa: PLC0415
22872287

22882288
data = await self._state.http.guild_webhooks(self.id)
22892289
return [Webhook.from_state(d, state=self._state) for d in data]
@@ -2373,7 +2373,7 @@ async def create_template(self, *, name: str, description: str | utils.Undefined
23732373
description: :class:`str`
23742374
The description of the template.
23752375
"""
2376-
from .template import Template
2376+
from .template import Template # noqa: PLC0415
23772377

23782378
payload = {"name": name}
23792379

@@ -2919,9 +2919,7 @@ async def create_role(
29192919
fields["colors"] = actual_colours._to_dict()
29202920
else:
29212921
raise InvalidArgument(
2922-
"colours parameter must be of type RoleColours, not {0.__class__.__name__}".format(
2923-
actual_colours
2924-
)
2922+
"colours parameter must be of type RoleColours, not {}".format(actual_colours.__class__.__name__)
29252923
)
29262924

29272925
if hoist is not MISSING:

0 commit comments

Comments
 (0)