Skip to content

Commit d94ae4e

Browse files
committed
Refactor import statements and improve code formatting for consistency
1 parent 64e8bf6 commit d94ae4e

24 files changed

+173
-174
lines changed

discohook/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .embed import Embed
2626
from .emoji import PartialEmoji
2727
from .enums import *
28-
from .errors import InteractionException, HTTPException
28+
from .errors import HTTPException, InteractionException
2929
from .file import File
3030
from .guild import Guild, PartialGuild
3131
from .interaction import Interaction
@@ -35,7 +35,7 @@
3535
from .models import AllowedMentions, MessageReference
3636
from .option import Choice, Option
3737
from .permission import Permission
38-
from .poll import Poll, PollAnswer, PollLayoutType, PollMedia, PollAnswerCount
38+
from .poll import Poll, PollAnswer, PollAnswerCount, PollLayoutType, PollMedia
3939
from .role import PartialRole, Role
4040
from .select import Select, SelectOption
4141
from .user import User

discohook/adapter.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ async def send_modal(self, modal: Union[Modal, Any]) -> InteractionResponse:
227227
InteractionType.component,
228228
InteractionType.app_command,
229229
):
230-
raise InteractionTypeMismatch(f"Method not supported for {self.inter.type}", self.inter)
230+
raise InteractionTypeMismatch(
231+
f"Method not supported for {self.inter.type}", self.inter
232+
)
231233
self.inter.client.active_components[modal.custom_id] = modal
232234
payload = {
233235
"data": modal.to_dict(),
@@ -249,7 +251,9 @@ async def autocomplete(self, choices: List[Choice]):
249251
The choices to send
250252
"""
251253
if self.inter.type != InteractionType.autocomplete:
252-
raise InteractionTypeMismatch(f"Method not supported for {self.inter.type}", self.inter)
254+
raise InteractionTypeMismatch(
255+
f"Method not supported for {self.inter.type}", self.inter
256+
)
253257
choices = choices[:25]
254258
payload = {
255259
"type": InteractionCallbackType.autocomplete,
@@ -297,7 +301,9 @@ async def defer(
297301
if ephemeral:
298302
payload["data"] = {"flags": 64}
299303
else:
300-
raise InteractionTypeMismatch(f"Method not supported for {self.inter.type}", self.inter)
304+
raise InteractionTypeMismatch(
305+
f"Method not supported for {self.inter.type}", self.inter
306+
)
301307

302308
self.inter._responded = True
303309
await self.inter.client.http.send_interaction_callback(
@@ -311,7 +317,9 @@ async def require_premium(self):
311317
This method is only available for applications with a premium SKU set up
312318
"""
313319
if self.inter.type == InteractionType.autocomplete:
314-
raise InteractionTypeMismatch(f"Method not supported for {self.inter.type}", self.inter)
320+
raise InteractionTypeMismatch(
321+
f"Method not supported for {self.inter.type}", self.inter
322+
)
315323
payload = {
316324
"data": {},
317325
"type": InteractionCallbackType.premium_required,
@@ -365,7 +373,9 @@ async def update_message(
365373
self.inter.type == InteractionType.component
366374
or self.inter.type == InteractionType.modal_submit
367375
):
368-
raise InteractionTypeMismatch(f"Method not supported for {self.inter.type}", self.inter)
376+
raise InteractionTypeMismatch(
377+
f"Method not supported for {self.inter.type}", self.inter
378+
)
369379

370380
payload = _EditingPayload(
371381
content=content,

discohook/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from starlette.requests import Request
77
from starlette.responses import JSONResponse
88

9-
from .component import Component
109
from .channel import Channel, PartialChannel
1110
from .command import ApplicationCommand
11+
from .component import Component
1212
from .dash import dashboard
1313
from .embed import Embed
1414
from .errors import InteractionException
@@ -544,4 +544,4 @@ async def delete_application_emoji(self, emoji_id: str):
544544
emoji_id: str
545545
The ID of the emoji.
546546
"""
547-
await self.http.delete_application_emoji(emoji_id)
547+
await self.http.delete_application_emoji(emoji_id)

discohook/command.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
from typing import Any, Dict, List, Optional, Union
33

44
from .component import Interactable
5-
from .enums import (
6-
ApplicationCommandOptionType,
7-
ApplicationCommandType,
8-
ApplicationIntegrationType,
9-
InteractionContextType,
10-
)
5+
from .enums import (ApplicationCommandOptionType, ApplicationCommandType,
6+
ApplicationIntegrationType, InteractionContextType)
117
from .option import Option
128
from .permission import Permission
139
from .utils import Handler, find_description

discohook/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from .enums import ComponentType
66

77
if TYPE_CHECKING:
8-
from .interaction import Interaction
98
from .errors import InteractionException
9+
from .interaction import Interaction
1010

1111

1212
class Interactable:

discohook/errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, TYPE_CHECKING
1+
from typing import TYPE_CHECKING, Any
22

33
import aiohttp
44

@@ -14,6 +14,7 @@ def __init__(self, message: str, interaction: "Interaction"):
1414
self.interaction = interaction
1515
super().__init__(message)
1616

17+
1718
class InteractionTypeMismatch(InteractionException):
1819
"""Raised when the interaction type is not the expected type."""
1920

discohook/handler.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@
66
from starlette.responses import JSONResponse, Response
77

88
from .command import ApplicationCommand, ApplicationCommandOptionType
9-
from .enums import (
10-
ApplicationCommandType,
11-
ComponentType,
12-
InteractionCallbackType,
13-
InteractionType,
14-
)
15-
from .errors import CheckFailure, UnknownInteractionType, InteractionException
9+
from .enums import (ApplicationCommandType, ComponentType,
10+
InteractionCallbackType, InteractionType)
11+
from .errors import CheckFailure, InteractionException, UnknownInteractionType
1612
from .interaction import Interaction
17-
from .resolver import (
18-
build_context_menu_param,
19-
build_modal_params,
20-
build_select_menu_values,
21-
build_slash_command_params,
22-
)
13+
from .resolver import (build_context_menu_param, build_modal_params,
14+
build_select_menu_values, build_slash_command_params)
2315

2416

2517
def _build_key(interaction: Interaction) -> str:
@@ -65,7 +57,7 @@ async def _handler(request: Request):
6557
if not isinstance(result, bool):
6658
raise CheckFailure(
6759
f"check returned {type(result)}, expected bool",
68-
interaction
60+
interaction,
6961
)
7062
if not all(results):
7163
raise CheckFailure(f"command checks failed", interaction)
@@ -134,7 +126,7 @@ async def _handler(request: Request):
134126
if not isinstance(result, bool):
135127
raise CheckFailure(
136128
f"check returned {type(result)}, expected bool",
137-
interaction
129+
interaction,
138130
)
139131
if not all(results):
140132
raise CheckFailure("component checks failed", interaction)
@@ -152,12 +144,18 @@ async def _handler(request: Request):
152144
except Exception as e:
153145
if not component._error_handler:
154146
raise e
155-
await component._error_handler(InteractionException(str(e), interaction))
147+
await component._error_handler(
148+
InteractionException(str(e), interaction)
149+
)
156150
else:
157-
raise UnknownInteractionType(f"unknown interaction type {interaction.type}", interaction)
151+
raise UnknownInteractionType(
152+
f"unknown interaction type {interaction.type}", interaction
153+
)
158154
except Exception as e:
159155
if request.app._interaction_error_handler:
160-
await request.app._interaction_error_handler(InteractionException(str(e), interaction))
156+
await request.app._interaction_error_handler(
157+
InteractionException(str(e), interaction)
158+
)
161159
return Response(status_code=500)
162160
else:
163161
raise e from None

discohook/https.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import aiohttp
44

5-
from .errors import HTTPException
65
from . import __url__, __version__
6+
from .errors import HTTPException
77

88
if TYPE_CHECKING:
99
from .client import Client

discohook/params.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import mimetypes
33
from enum import Enum, IntEnum
4-
from typing import Any, Dict, List, Optional, TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
55

66
import aiohttp
77

@@ -18,22 +18,22 @@
1818

1919
class _SendingPayload:
2020
def __init__(
21-
self,
22-
*,
23-
content: Optional[str] = None,
24-
embed: Optional[Embed] = None,
25-
embeds: Optional[List[Embed]] = None,
26-
view: Optional[View] = None,
27-
tts: Optional[bool] = False,
28-
file: Optional[File] = None,
29-
files: Optional[List[File]] = None,
30-
ephemeral: Optional[bool] = False,
31-
allowed_mentions: Optional[AllowedMentions] = None,
32-
message_reference: Optional[MessageReference] = None,
33-
sticker_ids: Optional[List[str]] = None,
34-
suppress_embeds: Optional[bool] = False,
35-
supress_notifications: Optional[bool] = False,
36-
poll: Optional["Poll"] = None,
21+
self,
22+
*,
23+
content: Optional[str] = None,
24+
embed: Optional[Embed] = None,
25+
embeds: Optional[List[Embed]] = None,
26+
view: Optional[View] = None,
27+
tts: Optional[bool] = False,
28+
file: Optional[File] = None,
29+
files: Optional[List[File]] = None,
30+
ephemeral: Optional[bool] = False,
31+
allowed_mentions: Optional[AllowedMentions] = None,
32+
message_reference: Optional[MessageReference] = None,
33+
sticker_ids: Optional[List[str]] = None,
34+
suppress_embeds: Optional[bool] = False,
35+
supress_notifications: Optional[bool] = False,
36+
poll: Optional["Poll"] = None,
3737
):
3838
self.content = content
3939
self.embed = embed
@@ -64,7 +64,7 @@ def _merge_fields(self):
6464

6565
@staticmethod
6666
def _create_form(
67-
payload: Dict[str, Any], files: Optional[List[File]] = None
67+
payload: Dict[str, Any], files: Optional[List[File]] = None
6868
) -> aiohttp.MultipartWriter:
6969
form = aiohttp.MultipartWriter("form-data")
7070
# noinspection PyTypeChecker
@@ -137,23 +137,23 @@ def to_dict(self, payload_type: Optional[Enum] = None, **kwargs) -> Dict[str, An
137137
return {"data": data, "type": int(payload_type.value)}
138138

139139
def to_form(
140-
self, payload_type: Optional[Enum] = None, **kwargs
140+
self, payload_type: Optional[Enum] = None, **kwargs
141141
) -> aiohttp.MultipartWriter:
142142
return self._create_form(self.to_dict(payload_type, **kwargs), self.files)
143143

144144

145145
class _EditingPayload(_SendingPayload):
146146
def __init__(
147-
self,
148-
*,
149-
content: Optional[str] = MISSING,
150-
embed: Optional[Embed] = MISSING,
151-
embeds: Optional[List[Embed]] = MISSING,
152-
view: Optional[View] = MISSING,
153-
tts: Optional[bool] = MISSING,
154-
file: Optional[File] = MISSING,
155-
files: Optional[List[File]] = MISSING,
156-
suppress_embeds: Optional[bool] = MISSING,
147+
self,
148+
*,
149+
content: Optional[str] = MISSING,
150+
embed: Optional[Embed] = MISSING,
151+
embeds: Optional[List[Embed]] = MISSING,
152+
view: Optional[View] = MISSING,
153+
tts: Optional[bool] = MISSING,
154+
file: Optional[File] = MISSING,
155+
files: Optional[List[File]] = MISSING,
156+
suppress_embeds: Optional[bool] = MISSING,
157157
):
158158
super().__init__(
159159
content=content,
@@ -203,7 +203,7 @@ def _handle_edit_params(self):
203203
return payload
204204

205205
def to_dict(
206-
self, payload_type: Optional[IntEnum] = None, **kwargs
206+
self, payload_type: Optional[IntEnum] = None, **kwargs
207207
) -> Dict[str, Any]:
208208
data = self._handle_edit_params()
209209
data.update(kwargs)
@@ -212,6 +212,6 @@ def to_dict(
212212
return {"data": data, "type": payload_type}
213213

214214
def to_form(
215-
self, payload_type: Optional[Enum] = None, **kwargs
215+
self, payload_type: Optional[Enum] = None, **kwargs
216216
) -> aiohttp.MultipartWriter:
217217
return self._create_form(self.to_dict(payload_type, **kwargs), self.files)

discohook/poll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, Tuple
2+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
33

44
from .emoji import PartialEmoji
55
from .enums import PollLayoutType

0 commit comments

Comments
 (0)