Skip to content

Commit 2007918

Browse files
style(pre-commit): auto fixes from pre-commit.com hooks
1 parent 49e537f commit 2007918

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

discord/components.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
from .types.components import MediaGalleryComponent as MediaGalleryComponentPayload
5555
from .types.components import MediaGalleryItem as MediaGalleryItemPayload
5656
from .types.components import SectionComponent as SectionComponentPayload
57+
from .types.components import SelectDefaultValue as SelectDefaultValuePayload
5758
from .types.components import SelectMenu as SelectMenuPayload
5859
from .types.components import SelectOption as SelectOptionPayload
5960
from .types.components import SeparatorComponent as SeparatorComponentPayload
6061
from .types.components import TextDisplayComponent as TextDisplayComponentPayload
6162
from .types.components import ThumbnailComponent as ThumbnailComponentPayload
6263
from .types.components import UnfurledMediaItem as UnfurledMediaItemPayload
63-
from .types.components import SelectDefaultValue as SelectDefaultValuePayload
6464

6565
__all__ = (
6666
"Component",
@@ -459,7 +459,9 @@ def __init__(self, data: SelectMenuPayload):
459459
try_enum(ChannelType, ct) for ct in data.get("channel_types", [])
460460
]
461461
self.required: bool | None = data.get("required")
462-
self.default_values: list[SelectDefaultValue] = SelectDefaultValue._from_data(data.get("default_values"))
462+
self.default_values: list[SelectDefaultValue] = SelectDefaultValue._from_data(
463+
data.get("default_values")
464+
)
463465

464466
def to_dict(self) -> SelectMenuPayload:
465467
payload: SelectMenuPayload = {
@@ -511,10 +513,15 @@ def __init__(
511513
self.type: SelectDefaultValueType = type
512514

513515
@classmethod
514-
def _from_data(cls, default_values: list[SelectDefaultValuePayload] | None) -> list[SelectDefaultValue]:
516+
def _from_data(
517+
cls, default_values: list[SelectDefaultValuePayload] | None
518+
) -> list[SelectDefaultValue]:
515519
if not default_values:
516520
return []
517-
return [cls(id=int(d['id']), type=try_enum(SelectDefaultValueType, d['type'])) for d in default_values]
521+
return [
522+
cls(id=int(d["id"]), type=try_enum(SelectDefaultValueType, d["type"]))
523+
for d in default_values
524+
]
518525

519526
def to_dict(self) -> SelectDefaultValuePayload:
520527
return {

discord/types/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
ButtonStyle = Literal[1, 2, 3, 4, 5, 6]
3838
InputTextStyle = Literal[1, 2]
3939
SeparatorSpacingSize = Literal[1, 2]
40-
SelectDefaultValueType = Literal['channel', 'role', 'user']
40+
SelectDefaultValueType = Literal["channel", "role", "user"]
4141

4242

4343
class BaseComponent(TypedDict):

discord/ui/select.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525

2626
from __future__ import annotations
2727

28-
from collections.abc import Sequence
2928
import inspect
3029
import os
30+
from collections.abc import Sequence
3131
from typing import TYPE_CHECKING, Callable, TypeVar
3232

3333
from .. import abc
3434
from ..channel import _threaded_guild_channel_factory
35-
from ..components import SelectMenu, SelectOption, SelectDefaultValue
35+
from ..components import SelectDefaultValue, SelectMenu, SelectOption
3636
from ..emoji import AppEmoji, GuildEmoji
3737
from ..enums import ChannelType, ComponentType, SelectDefaultValueType
3838
from ..errors import InvalidArgument
@@ -248,18 +248,37 @@ def __init__(
248248
)
249249
self.row = row
250250

251-
def _handle_default_values(self, default_values: Sequence[abc.Snowflake] | None, select_type: ComponentType) -> list[SelectDefaultValue]:
251+
def _handle_default_values(
252+
self, default_values: Sequence[abc.Snowflake] | None, select_type: ComponentType
253+
) -> list[SelectDefaultValue]:
252254
if not default_values:
253255
return []
254256

255257
ret = []
256258

257-
instances_mapping: dict[type, tuple[tuple[ComponentType, ...], SelectDefaultValueType]] = {
258-
Role: ((ComponentType.role_select, ComponentType.mentionable_select), SelectDefaultValueType.role),
259-
User: ((ComponentType.user_select, ComponentType.mentionable_select), SelectDefaultValueType.user),
260-
Member: ((ComponentType.user_select, ComponentType.mentionable_select), SelectDefaultValueType.user),
261-
abc.User: ((ComponentType.user_select, ComponentType.mentionable_select), SelectDefaultValueType.user),
262-
abc.GuildChannel: ((ComponentType.channel_select,), SelectDefaultValueType.channel),
259+
instances_mapping: dict[
260+
type, tuple[tuple[ComponentType, ...], SelectDefaultValueType]
261+
] = {
262+
Role: (
263+
(ComponentType.role_select, ComponentType.mentionable_select),
264+
SelectDefaultValueType.role,
265+
),
266+
User: (
267+
(ComponentType.user_select, ComponentType.mentionable_select),
268+
SelectDefaultValueType.user,
269+
),
270+
Member: (
271+
(ComponentType.user_select, ComponentType.mentionable_select),
272+
SelectDefaultValueType.user,
273+
),
274+
abc.User: (
275+
(ComponentType.user_select, ComponentType.mentionable_select),
276+
SelectDefaultValueType.user,
277+
),
278+
abc.GuildChannel: (
279+
(ComponentType.channel_select,),
280+
SelectDefaultValueType.channel,
281+
),
263282
}
264283

265284
for dv in default_values:
@@ -276,10 +295,14 @@ def _handle_default_values(self, default_values: Sequence[abc.Snowflake] | None,
276295
try:
277296
sel_type, def_type = instances_mapping[obj_type]
278297
except KeyError:
279-
raise TypeError(f'{dv.__class__.__name__} is not a valid instance for default_values')
298+
raise TypeError(
299+
f"{dv.__class__.__name__} is not a valid instance for default_values"
300+
)
280301

281302
if select_type not in sel_type:
282-
raise TypeError(f'{dv.__class__.__name__} objects can not be set as a default value for {select_type.value} selects')
303+
raise TypeError(
304+
f"{dv.__class__.__name__} objects can not be set as a default value for {select_type.value} selects"
305+
)
283306

284307
ret.append(SelectDefaultValue(id=obj_id, type=def_type))
285308

@@ -390,7 +413,9 @@ def default_values(self) -> list[SelectDefaultValue]:
390413
return self._underlying.default_values
391414

392415
@default_values.setter
393-
def default_values(self, values: list[SelectDefaultValue | abc.Snowflake] | None) -> None:
416+
def default_values(
417+
self, values: list[SelectDefaultValue | abc.Snowflake] | None
418+
) -> None:
394419
default_values = self._handle_default_values(values, self.type)
395420
self._underlying.default_values = default_values
396421

@@ -424,7 +449,9 @@ def add_default_value(
424449
The number of default select values exceeds 25.
425450
"""
426451
if type is MISSING and self.type is ComponentType.mentionable_select:
427-
raise TypeError('type is required when select is of type mentionable_select')
452+
raise TypeError(
453+
"type is required when select is of type mentionable_select"
454+
)
428455

429456
types = {
430457
ComponentType.user_select: SelectDefaultValueType.user,
@@ -784,7 +811,9 @@ def select(
784811
raise TypeError("channel_types may only be specified for channel selects")
785812

786813
if default_values is not None and select_type is ComponentType.string_select:
787-
raise TypeError("default_values may only be specified for selects other than string selects")
814+
raise TypeError(
815+
"default_values may only be specified for selects other than string selects"
816+
)
788817

789818
def decorator(func: ItemCallbackType) -> ItemCallbackType:
790819
if not inspect.iscoroutinefunction(func):

0 commit comments

Comments
 (0)