diff --git a/CHANGELOG.md b/CHANGELOG.md index c42ff5f256..7e5a597043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,18 @@ These changes are available on the `master` branch, but have not yet been releas ### Changed +- Changed `Label.set_radio_group()` and `Label.set_file_upload()` to no longer accept a + nullable `required` value. + ([#3337](https://github.com/Pycord-Development/pycord/pull/3337)) + ### Fixed - Fix `TypeError` when accessing `ApplicationCommand.guild_only` or `SlashCommandGroup.guild_only` when `contexts` is `None`. ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) +- Fix `option` keyword argument in `Label.set_radio_group()` and + `Label.set_checkbox_group()` that caused `TypeError` when used. + ([#3337](https://github.com/Pycord-Development/pycord/pull/3337)) - Fix `SyntaxWarning` about `return` in a `finally` block raised on Python 3.14+ ([#3332](https://github.com/Pycord-Development/pycord/pull/3334)) diff --git a/discord/ui/checkbox.py b/discord/ui/checkbox.py index 5915f9938d..30784b2e06 100644 --- a/discord/ui/checkbox.py +++ b/discord/ui/checkbox.py @@ -47,8 +47,8 @@ class Checkbox(ModalItem): ---------- custom_id: Optional[:class:`str`] The ID of the checkbox that gets received during an interaction. - default: Optional[:class:`bool`] - Whether this checkbox is selected by default or not. + default: :class:`bool` + Whether this checkbox is selected by default or not. Defaults to ``False``. id: Optional[:class:`int`] The checkbox's ID. """ @@ -71,6 +71,7 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if not isinstance(default, bool): raise TypeError(f"default must be bool, not {default.__class__.__name__}") custom_id = os.urandom(16).hex() if custom_id is None else custom_id diff --git a/discord/ui/checkbox_group.py b/discord/ui/checkbox_group.py index ed155898ab..abeb75466e 100644 --- a/discord/ui/checkbox_group.py +++ b/discord/ui/checkbox_group.py @@ -61,7 +61,7 @@ class CheckboxGroup(ModalItem): max_values: Optional[:class:`int`] The maximum number of options that can be selected. Must be between 1 and 10, inclusive. - required: Optional[:class:`bool`] + required: :class:`bool` Whether an option selection is required or not. Defaults to ``True``. id: Optional[:class:`int`] The checkbox group's ID. @@ -95,6 +95,7 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if not isinstance(required, bool): raise TypeError(f"required must be bool not {required.__class__.__name__}") custom_id = os.urandom(16).hex() if custom_id is None else custom_id diff --git a/discord/ui/file_upload.py b/discord/ui/file_upload.py index 784b8f6733..7ab6182f52 100644 --- a/discord/ui/file_upload.py +++ b/discord/ui/file_upload.py @@ -54,7 +54,7 @@ class FileUpload(ModalItem): max_values: Optional[:class:`int`] The maximum number of files that can be uploaded. Must be between 1 and 10, inclusive. - required: Optional[:class:`bool`] + required: :class:`bool` Whether the file upload field is required or not. Defaults to ``True``. id: Optional[:class:`int`] The file upload field's ID. @@ -86,8 +86,9 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if not isinstance(required, bool): - raise TypeError(f"required must be bool not {required.__class__.__name__}") # type: ignore + raise TypeError(f"required must be bool not {required.__class__.__name__}") custom_id = os.urandom(16).hex() if custom_id is None else custom_id self._attachments: list[Attachment] | None = None diff --git a/discord/ui/label.py b/discord/ui/label.py index 720b02b226..cbec8ff1bb 100644 --- a/discord/ui/label.py +++ b/discord/ui/label.py @@ -31,20 +31,13 @@ CheckboxGroupOption, ) from ..components import Label as LabelComponent -from ..components import ( - RadioGroupOption, - SelectDefaultValue, - SelectOption, - _component_factory, -) -from ..enums import ButtonStyle, ChannelType, ComponentType, InputTextStyle -from ..utils import find, get -from .button import Button +from ..components import RadioGroupOption, SelectDefaultValue, SelectOption +from ..enums import ChannelType, ComponentType, InputTextStyle from .checkbox import Checkbox from .checkbox_group import CheckboxGroup from .file_upload import FileUpload from .input_text import InputText -from .item import ItemCallbackType, ModalItem +from .item import ModalItem from .radio_group import RadioGroup from .select import Select @@ -53,9 +46,7 @@ if TYPE_CHECKING: from typing_extensions import Self - from ..emoji import AppEmoji, GuildEmoji from ..interactions import Interaction - from ..partial_emoji import PartialEmoji, _EmojiTag from ..types.components import LabelComponent as LabelComponentPayload from .modal import DesignerModal @@ -264,7 +255,7 @@ def set_select( options: list[SelectOption] | None = ..., required: bool = ..., id: int | None = ..., - ) -> None: ... + ) -> Self: ... @overload def set_select( @@ -279,7 +270,7 @@ def set_select( required: bool = ..., id: int | None = ..., default_values: Sequence[SelectDefaultValue] | None = ..., - ) -> None: ... + ) -> Self: ... @overload def set_select( @@ -297,7 +288,7 @@ def set_select( required: bool = ..., id: int | None = ..., default_values: Sequence[SelectDefaultValue] | None = ..., - ) -> None: ... + ) -> Self: ... def set_select( self, @@ -371,7 +362,7 @@ def set_file_upload( custom_id: str | None = None, min_values: int | None = None, max_values: int | None = None, - required: bool | None = True, + required: bool = True, id: int | None = None, ) -> Self: """Set this label's item to a file upload. @@ -389,7 +380,7 @@ def set_file_upload( max_values: Optional[:class:`int`] The maximum number of files that can be uploaded. Must be between 1 and 10, inclusive. - required: Optional[:class:`bool`] + required: :class:`bool` Whether the file upload field is required or not. Defaults to ``True``. id: Optional[:class:`int`] The file upload field's ID. @@ -410,7 +401,7 @@ def set_radio_group( *, custom_id: str | None = None, options: list[RadioGroupOption] | None = None, - required: bool | None = True, + required: bool = True, id: int | None = None, ) -> Self: """Set this label's item to a radio group. @@ -432,7 +423,7 @@ def set_radio_group( radio = RadioGroup( custom_id=custom_id, - option=options, + options=options, required=required, id=id, ) @@ -474,7 +465,7 @@ def set_checkbox_group( checkboxes = CheckboxGroup( custom_id=custom_id, - option=options, + options=options, min_values=min_values, max_values=max_values, required=required, diff --git a/discord/ui/radio_group.py b/discord/ui/radio_group.py index 7a01501776..075ce08675 100644 --- a/discord/ui/radio_group.py +++ b/discord/ui/radio_group.py @@ -79,6 +79,7 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if not isinstance(required, bool): raise TypeError(f"required must be bool not {required.__class__.__name__}") custom_id = os.urandom(16).hex() if custom_id is None else custom_id diff --git a/discord/ui/select.py b/discord/ui/select.py index df18c9385c..cd7e17dc7e 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -236,6 +236,24 @@ def __init__( default_values: Sequence[SelectDefaultValue | ST] | None = ..., ) -> None: ... + @overload + def __init__( + self, + select_type: ComponentType = ..., + *, + custom_id: str | None = ..., + placeholder: str | None = ..., + min_values: int = ..., + max_values: int = ..., + options: list[SelectOption] | None = ..., + channel_types: list[ChannelType] | None = ..., + disabled: bool = ..., + row: int | None = ..., + id: int | None = ..., + required: bool | None = ..., + default_values: Sequence[SelectDefaultValue | ST] | None = ..., + ) -> None: ... + def __init__( self, select_type: ComponentType = ComponentType.string_select,