Skip to content

Commit a0ac891

Browse files
committed
merge upstream
2 parents f8e990a + 2007918 commit a0ac891

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
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: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
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 ..channel import _threaded_guild_channel_factory
34-
from ..components import SelectMenu, SelectOption, SelectDefaultValue
34+
from ..components import SelectDefaultValue, SelectMenu, SelectOption
3535
from ..emoji import AppEmoji, GuildEmoji
3636
from ..enums import ChannelType, ComponentType, SelectDefaultValueType
3737
from ..errors import InvalidArgument
@@ -255,12 +255,29 @@ def _handle_default_values(self, default_values: Sequence[Snowflake] | None, sel
255255

256256
from discord import abc # > circular import <
257257

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

266283
for dv in default_values:
@@ -277,10 +294,14 @@ def _handle_default_values(self, default_values: Sequence[Snowflake] | None, sel
277294
try:
278295
sel_type, def_type = instances_mapping[obj_type]
279296
except KeyError:
280-
raise TypeError(f'{dv.__class__.__name__} is not a valid instance for default_values')
297+
raise TypeError(
298+
f"{dv.__class__.__name__} is not a valid instance for default_values"
299+
)
281300

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

285306
ret.append(SelectDefaultValue(id=obj_id, type=def_type))
286307

@@ -425,7 +446,9 @@ def add_default_value(
425446
The number of default select values exceeds 25.
426447
"""
427448
if type is MISSING and self.type is ComponentType.mentionable_select:
428-
raise TypeError('type is required when select is of type mentionable_select')
449+
raise TypeError(
450+
"type is required when select is of type mentionable_select"
451+
)
429452

430453
types = {
431454
ComponentType.user_select: SelectDefaultValueType.user,
@@ -785,7 +808,9 @@ def select(
785808
raise TypeError("channel_types may only be specified for channel selects")
786809

787810
if default_values is not None and select_type is ComponentType.string_select:
788-
raise TypeError("default_values may only be specified for selects other than string selects")
811+
raise TypeError(
812+
"default_values may only be specified for selects other than string selects"
813+
)
789814

790815
def decorator(func: ItemCallbackType) -> ItemCallbackType:
791816
if not inspect.iscoroutinefunction(func):

0 commit comments

Comments
 (0)