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

Code before:
        ComponentType.channel_select,
        ComponentType.mentionable_select,
    ):
        raise TypeError('component_type must be one of user_select, role_select, channel_select, or mentionable_select')

    from ..app_commands import AppCommandChannel, AppCommandThread

    cls_to_type: Dict[Type[ValidDefaultValues], SelectDefaultValueType] = {
        User: SelectDefaultValueType.user,
        Member: SelectDefaultValueType.user,
        Role: SelectDefaultValueType.role,
        GuildChannel: SelectDefaultValueType.channel,
        AppCommandChannel: SelectDefaultValueType.channel,
        AppCommandThread: SelectDefaultValueType.channel,
        Thread: SelectDefaultValueType.channel,
    }
    type_to_supported_classes: Dict[ValidSelectType, Tuple[Type[ValidDefaultValues], ...]] = {
        ComponentType.user_select: (User, Member, Object),
        ComponentType.role_select: (Role, Object),
        ComponentType.channel_select: (GuildChannel, AppCommandChannel, AppCommandThread, Thread, Object),
        ComponentType.mentionable_select: (User, Member, Role, Object),
    }

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

        object_type = obj.__class__ if not isinstance(obj, Object) else obj.type

        print(object_type, component_type, object_type == Object)

        if object_type not in type_to_supported_classes[component_type]:
            supported_classes = [c.__name__ for c in type_to_supported_classes[component_type]]
            if len(supported_classes) > 2:
                supported_classes = ', '.join(supported_classes[:-1]) + f', or {supported_classes[-1]}'
            elif len(supported_classes) == 2:
                supported_classes = f'{supported_classes[0]} or {supported_classes[1]}'
            else:
                supported_classes = supported_classes[0]

            raise TypeError(f'Expected an instance of {supported_classes} not {object_type.__name__}')

        if object_type == Object:
            if component_type is ComponentType.mentionable_select:
                raise ValueError(
                    'Object must have a type specified for the chosen select type. Please pass one using the `type`` kwarg.'
                )
            elif component_type is ComponentType.user_select:
                object_type = User

Review comment (refactor):
```suggestion
            # TODO: split this into a util function
            supported_classes = [c.__name__ for c in type_to_supported_classes[component_type]]
```

A note for myself please :)

Code after:
        User: SelectDefaultValueType.user,
        Member: SelectDefaultValueType.user,
        Role: SelectDefaultValueType.role,
        GuildChannel: SelectDefaultValueType.channel,
        AppCommandChannel: SelectDefaultValueType.channel,
        AppCommandThread: SelectDefaultValueType.channel,
        Thread: SelectDefaultValueType.channel,
    }
    type_to_supported_classes: Dict[ValidSelectType, Tuple[Type[ValidDefaultValues], ...]] = {
        ComponentType.user_select: (User, Member, Object),
        ComponentType.role_select: (Role, Object),
        ComponentType.channel_select: (GuildChannel, AppCommandChannel, AppCommandThread, Thread, Object),
        ComponentType.mentionable_select: (User, Member, Role, Object),
    }

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

        object_type = obj.__class__ if not isinstance(obj, Object) else obj.type

        if object_type not in type_to_supported_classes[component_type]:
            # TODO: split this into a util function
            supported_classes = [c.__name__ for c in type_to_supported_classes[component_type]]
            if len(supported_classes) > 2:
                supported_classes = ', '.join(supported_classes[:-1]) + f', or {supported_classes[-1]}'
            elif len(supported_classes) == 2:
                supported_classes = f'{supported_classes[0]} or {supported_classes[1]}'
            else:
                supported_classes = supported_classes[0]

            raise TypeError(f'Expected an instance of {supported_classes} not {object_type.__name__}')

        if object_type is Object:
            if component_type is ComponentType.mentionable_select:
                raise ValueError(
                    'Object must have a type specified for the chosen select type. Please pass one using the `type`` kwarg.'
                )
            elif component_type is ComponentType.user_select:
                object_type = User
            elif component_type is ComponentType.role_select:
                object_type = Role
            elif component_type is ComponentType.channel_select:
                object_type = GuildChannel

        values.append(SelectDefaultValue(id=obj.id, type=cls_to_type[object_type]))

    return values