Repository: Rapptz/discord.py
File: discord/ui/select.py (Python)

Code before:
            Role: SelectDefaultValueType.role,
            GuildChannel: SelectDefaultValueType.channel,
            AppCommandChannel: SelectDefaultValueType.channel,
            AppCommandThread: SelectDefaultValueType.channel,
            Thread: SelectDefaultValueType.channel,
        }

        values: List[SelectDefaultValue] = []
        for obj in defaults:
            if isinstance(obj, SelectDefaultValue):
                values.append(obj)
                continue

            if not value_type and isinstance(obj, Object) and obj.type == Object:
                raise ValueError(
                    "Object must have a type specified for the chosen select type. Please pass one using the `type` kwarg."
                )

            if not isinstance(obj, (Object, Role, Member, User, GuildChannel, AppCommandChannel, AppCommandThread, Thread)):
                supported_classes = ', '.join(str(v) for v in default_type_to_enum)
                raise TypeError(f"Invalid type {obj.__class__!r} for default value. Must be one of {supported_classes}")

            values.append(
                SelectDefaultValue(
                    id=obj.id,
                    type=value_type or default_type_to_enum[obj.__class__ if not isinstance(obj, Object) else obj.type],  # type: ignore
                )
            )

        return values


class Select(BaseSelect[V]):
    """Represents a UI select menu with a list of custom options. This is represented
    to the user as a dropdown menu.

    .. versionadded:: 2.0

    Parameters
    ------------
    custom_id: :class:`str`
        The ID of the select menu that gets received during an interaction.
        If not given then one is generated for you.
    placeholder: Optional[:class:`str`]
        The placeholder text that is shown if nothing is selected, if any.
    min_values: :class:`int`
        The minimum number of items that must be chosen for this select menu.
        Defaults to 1 and must be between 0 and 25.
    max_values: :class:`int`
        The maximum number of items that must be chosen for this select menu.
        Defaults to 1 and must be between 1 and 25.

Review comment (bug):
Please give this its own variable, it reads terribly.

On that note, as mentioned, it's buggy to coerce the value into the given `value_type`.

Code after:
    def placeholder(self, value: Optional[str]) -> None:
        if value is not None and not isinstance(value, str):
            raise TypeError('placeholder must be None or str')

        self._underlying.placeholder = value

    @property
    def min_values(self) -> int:
        """:class:`int`: The minimum number of items that must be chosen for this select menu."""
        return self._underlying.min_values

    @min_values.setter
    def min_values(self, value: int) -> None:
        self._underlying.min_values = int(value)

    @property
    def max_values(self) -> int:
        """:class:`int`: The maximum number of items that can be chosen for this select menu."""
        return self._underlying.max_values

    @max_values.setter
    def max_values(self, value: int) -> None:
        self._underlying.max_values = int(value)

    @property
    def disabled(self) -> bool:
        """:class:`bool`: Whether the select is disabled or not."""
        return self._underlying.disabled

    @disabled.setter
    def disabled(self, value: bool) -> None:
        self._underlying.disabled = bool(value)

    @property
    def width(self) -> int:
        return 5

    def to_component_dict(self) -> SelectMenuPayload:
        return self._underlying.to_dict()

    def _refresh_component(self, component: SelectMenu) -> None:
        self._underlying = component

    def _refresh_state(self, interaction: Interaction, data: SelectMessageComponentInteractionData) -> None:
        values = selected_values.get({})
        payload: List[PossibleValue]
        try:
            resolved = Namespace._get_resolved_items(interaction, data['resolved'])
            payload = list(resolved.values())
        except KeyError:
            payload = data.get("values", [])  # type: ignore