25
25
26
26
from __future__ import annotations
27
27
28
- from collections .abc import Sequence
29
28
import inspect
30
29
import os
30
+ from collections .abc import Sequence
31
31
from typing import TYPE_CHECKING , Callable , TypeVar
32
32
33
33
from ..channel import _threaded_guild_channel_factory
34
- from ..components import SelectMenu , SelectOption , SelectDefaultValue
34
+ from ..components import SelectDefaultValue , SelectMenu , SelectOption
35
35
from ..emoji import AppEmoji , GuildEmoji
36
36
from ..enums import ChannelType , ComponentType , SelectDefaultValueType
37
37
from ..errors import InvalidArgument
@@ -255,12 +255,29 @@ def _handle_default_values(self, default_values: Sequence[Snowflake] | None, sel
255
255
256
256
from discord import abc # > circular import <
257
257
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
+ ),
264
281
}
265
282
266
283
for dv in default_values :
@@ -277,10 +294,14 @@ def _handle_default_values(self, default_values: Sequence[Snowflake] | None, sel
277
294
try :
278
295
sel_type , def_type = instances_mapping [obj_type ]
279
296
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
+ )
281
300
282
301
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
+ )
284
305
285
306
ret .append (SelectDefaultValue (id = obj_id , type = def_type ))
286
307
@@ -425,7 +446,9 @@ def add_default_value(
425
446
The number of default select values exceeds 25.
426
447
"""
427
448
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
+ )
429
452
430
453
types = {
431
454
ComponentType .user_select : SelectDefaultValueType .user ,
@@ -785,7 +808,9 @@ def select(
785
808
raise TypeError ("channel_types may only be specified for channel selects" )
786
809
787
810
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
+ )
789
814
790
815
def decorator (func : ItemCallbackType ) -> ItemCallbackType :
791
816
if not inspect .iscoroutinefunction (func ):
0 commit comments