4545from ..threads import Thread
4646from ..user import User
4747from ..utils import MISSING
48+ from .core import ComponentLimits
4849from .item import ItemCallbackType , ModalItem , ViewItem
4950
5051__all__ = (
@@ -265,12 +266,24 @@ def __init__(
265266 super ().__init__ ()
266267 self ._selected_values : list [str ] = []
267268 self ._interaction : Interaction | None = None
268- if min_values < 0 or min_values > 25 :
269- raise ValueError ("min_values must be between 0 and 25" )
270- if max_values < 1 or max_values > 25 :
271- raise ValueError ("max_values must be between 1 and 25" )
272- if placeholder and len (placeholder ) > 150 :
273- raise ValueError ("placeholder must be 150 characters or fewer" )
269+ if (
270+ min_values < ComponentLimits .SELECT_MIN_VALUE_MIN
271+ or min_values > ComponentLimits .SELECT_MIN_VALUE_MAX
272+ ):
273+ raise ValueError (
274+ f"min_values must be between { ComponentLimits .SELECT_MIN_VALUE_MIN } and { ComponentLimits .SELECT_MIN_VALUE_MAX } "
275+ )
276+ if (
277+ max_values < ComponentLimits .SELECT_MAX_VALUE_MIN
278+ or max_values > ComponentLimits .SELECT_MAX_VALUE_MAX
279+ ):
280+ raise ValueError (
281+ f"max_values must be between { ComponentLimits .SELECT_MAX_VALUE_MIN } and { ComponentLimits .SELECT_MAX_VALUE_MAX } "
282+ )
283+ if placeholder and len (placeholder ) > ComponentLimits .SELECT_PLACEHOLDER_MAX :
284+ raise ValueError (
285+ f"placeholder must be { ComponentLimits .SELECT_PLACEHOLDER_MAX } characters or fewer"
286+ )
274287 if not isinstance (custom_id , str ) and custom_id is not None :
275288 raise TypeError (
276289 f"expected custom_id to be str, not { custom_id .__class__ .__name__ } "
@@ -377,8 +390,10 @@ def custom_id(self) -> str:
377390 def custom_id (self , value : str ):
378391 if not isinstance (value , str ):
379392 raise TypeError ("custom_id must be None or str" )
380- if len (value ) > 100 :
381- raise ValueError ("custom_id must be 100 characters or fewer" )
393+ if len (value ) > ComponentLimits .CUSTOM_ID_MAX :
394+ raise ValueError (
395+ f"custom_id must be { ComponentLimits .CUSTOM_ID_MAX } characters or fewer"
396+ )
382397 self .underlying .custom_id = value
383398 self ._provided_custom_id = value is not None
384399
@@ -391,8 +406,10 @@ def placeholder(self) -> str | None:
391406 def placeholder (self , value : str | None ):
392407 if value is not None and not isinstance (value , str ):
393408 raise TypeError ("placeholder must be None or str" )
394- if value and len (value ) > 150 :
395- raise ValueError ("placeholder must be 150 characters or fewer" )
409+ if value and len (value ) > ComponentLimits .SELECT_PLACEHOLDER_MAX :
410+ raise ValueError (
411+ f"placeholder must be { ComponentLimits .SELECT_PLACEHOLDER_MAX } characters or fewer"
412+ )
396413
397414 self .underlying .placeholder = value
398415
@@ -403,8 +420,13 @@ def min_values(self) -> int:
403420
404421 @min_values .setter
405422 def min_values (self , value : int ):
406- if value < 0 or value > 25 :
407- raise ValueError ("min_values must be between 0 and 25" )
423+ if (
424+ value < ComponentLimits .SELECT_MIN_VALUE_MIN
425+ or value > ComponentLimits .SELECT_MIN_VALUE_MAX
426+ ):
427+ raise ValueError (
428+ f"min_values must be between { ComponentLimits .SELECT_MIN_VALUE_MIN } and { ComponentLimits .SELECT_MIN_VALUE_MAX } "
429+ )
408430 self .underlying .min_values = int (value )
409431
410432 @property
@@ -414,8 +436,13 @@ def max_values(self) -> int:
414436
415437 @max_values .setter
416438 def max_values (self , value : int ):
417- if value < 1 or value > 25 :
418- raise ValueError ("max_values must be between 1 and 25" )
439+ if (
440+ value < ComponentLimits .SELECT_MAX_VALUE_MIN
441+ or value > ComponentLimits .SELECT_MAX_VALUE_MAX
442+ ):
443+ raise ValueError (
444+ f"max_values must be between { ComponentLimits .SELECT_MAX_VALUE_MIN } and { ComponentLimits .SELECT_MAX_VALUE_MAX } "
445+ )
419446 self .underlying .max_values = int (value )
420447
421448 @property
@@ -575,8 +602,10 @@ def append_default_value(
575602 if self .type is ComponentType .string_select :
576603 raise TypeError ("string_select selects do not allow default_values" )
577604
578- if len (self .default_values ) >= 25 :
579- raise ValueError ("maximum number of default values exceeded (25)" )
605+ if len (self .default_values ) >= ComponentLimits .SELECT_DEFAULT_VALUES_MAX :
606+ raise ValueError (
607+ f"maximum number of default values exceeded ({ ComponentLimits .SELECT_DEFAULT_VALUES_MAX } )"
608+ )
580609
581610 if not isinstance (value , SelectDefaultValue ):
582611 value = SelectDefaultValue ._handle_model (value )
@@ -654,7 +683,7 @@ def append_option(self, option: SelectOption) -> Self:
654683 if self .underlying .type is not ComponentType .string_select :
655684 raise Exception ("options can only be set on string selects" )
656685
657- if len (self .underlying .options ) > 25 :
686+ if len (self .underlying .options ) > ComponentLimits . SELECT_OPTIONS_MAX :
658687 raise ValueError ("maximum number of options already provided" )
659688
660689 self .underlying .options .append (option )
0 commit comments