Repository: hikari-py/hikari
Pull request #1580 (2023-04-02 20:40:44)

Remove deprecated functionality for 2.0.0.dev119


Patch:
diff --git a/changes/1580.breaking.md b/changes/1580.breaking.md
new file mode 100644
index 00000000..d1391854
--- /dev/null
+++ b/changes/1580.breaking.md
@@ -0,0 +1,3 @@
+Remove deprecated functionality for 2.0.0.dev119
+- Removed `TextInputBuilder.required` in favour of `TextInputBuilder.is_required`.
+- Removed the ability to pass `CommandChoices` instead of `AutocompleteChoiceBuilders` when making autocomplete responses.
diff --git a/hikari/api/rest.py b/hikari/api/rest.py
index 6d1b8aba..d276a988 100644
--- a/hikari/api/rest.py
+++ b/hikari/api/rest.py
@@ -7287,17 +7287,12 @@ def interaction_deferred_builder(
 
     @abc.abstractmethod
     def interaction_autocomplete_builder(
-        self,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
-        _stack_level: int = 0,
+        self, choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
     ) -> special_endpoints.InteractionAutocompleteBuilder:
         """Create a builder for an autocomplete interaction response.
 
-        .. deprecated:: 2.0.0.dev118
-            Passing `hikari.commands.CommandChoice`s here instead of
-            `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
+        choices : typing.Sequence[hikari.api.special_endpoints.AutocompleteChoiceBuilder]
+            The autocomplete choices.
 
         Returns
         -------
@@ -7671,17 +7666,10 @@ async def create_autocomplete_response(
         self,
         interaction: snowflakes.SnowflakeishOr[base_interactions.PartialInteraction],
         token: str,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
-        _stack_level: int = 0,
+        choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder],
     ) -> None:
         """Create the initial response for an autocomplete interaction.
 
-        .. deprecated:: 2.0.0.dev118
-            Passing `hikari.commands.CommandChoice`s here instead of
-            `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
-
         Parameters
         ----------
         interaction : hikari.snowflakes.SnowflakeishOr[hikari.interactions.base_interactions.PartialInteraction]
diff --git a/hikari/api/special_endpoints.py b/hikari/api/special_endpoints.py
index 3007afe2..113c0a5e 100644
--- a/hikari/api/special_endpoints.py
+++ b/hikari/api/special_endpoints.py
@@ -642,16 +642,13 @@ def choices(self) -> typing.Sequence[AutocompleteChoiceBuilder]:
         """Autocomplete choices."""
 
     @abc.abstractmethod
-    def set_choices(
-        self,
-        choices: typing.Union[typing.Sequence[commands.CommandChoice], typing.Sequence[AutocompleteChoiceBuilder]],
-        /,
-    ) -> Self:
+    def set_choices(self, choices: typing.Sequence[AutocompleteChoiceBuilder], /) -> Self:
         """Set autocomplete choices.
 
-        .. deprecated:: 2.0.0.dev118
-            Passing `hikari.commands.CommandChoice`s here instead of
-            `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
+        Parameters
+        ----------
+        choices : typing.Sequence[AutocompleteChoiceBuilder]
+            The choices to set.
 
         Returns
         -------
@@ -1832,11 +1829,6 @@ def placeholder(self) -> undefined.UndefinedOr[str]:
     def value(self) -> undefined.UndefinedOr[str]:
         """Pre-filled text that will be sent if the user does not write anything."""
 
-    @property
-    @abc.abstractmethod
-    def required(self) -> bool:
-        """Deprecated alias for `hikari.api.special_endpoints.TextInputBuilder`."""
-
     @property
     @abc.abstractmethod
     def is_required(self) -> bool:
diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py
index e2fda505..0df1fee5 100644
--- a/hikari/impl/rest.py
+++ b/hikari/impl/rest.py
@@ -75,7 +75,6 @@
 from hikari.interactions import base_interactions
 from hikari.internal import aio
 from hikari.internal import data_binding
-from hikari.internal import deprecation
 from hikari.internal import mentions
 from hikari.internal import net
 from hikari.internal import routes
@@ -3930,13 +3929,9 @@ def interaction_deferred_builder(
         return special_endpoints_impl.InteractionDeferredBuilder(type=type_)
 
     def interaction_autocomplete_builder(
-        self,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
-        _stack_level: int = 0,
+        self, choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
     ) -> special_endpoints.InteractionAutocompleteBuilder:
-        return special_endpoints_impl.InteractionAutocompleteBuilder(choices, _stack_level=_stack_level + 1)
+        return special_endpoints_impl.InteractionAutocompleteBuilder(choices)
 
     def interaction_message_builder(
         self, type_: typing.Union[base_interactions.ResponseType, int], /
@@ -4066,10 +4061,7 @@ async def create_autocomplete_response(
         self,
         interaction: snowflakes.SnowflakeishOr[base_interactions.PartialInteraction],
         token: str,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
-        _stack_level: int = 0,
+        choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder],
     ) -> None:
         route = routes.POST_INTERACTION_RESPONSE.compile(interaction=interaction, token=token)
 
@@ -4077,23 +4069,7 @@ async def create_autocomplete_response(
         body.put("type", base_interactions.ResponseType.AUTOCOMPLETE)
 
         data = data_binding.JSONObjectBuilder()
-        raw_choices: typing.List[typing.Dict[str, typing.Union[str, int, float]]] = []
-        warned = False
-
-        for choice in choices:
-            if not warned and isinstance(choice, commands.CommandChoice):
-                deprecation.warn_deprecated(
-                    "Passing CommandChoice",
-                    removal_version="2.0.0.dev119",
-                    additional_info="Use AutocompleteChoiceBuilder instead",
-                    quote=False,
-                    stack_level=3 + _stack_level,
-                )
-                warned = True
-
-            raw_choices.append({"name": choice.name, "value": choice.value})
-
-        data.put("choices", raw_choices)
+        data.put("choices", [{"name": choice.name, "value": choice.value} for choice in choices])
 
         body.put("data", data)
         await self._request(route, json=body, auth=None)
diff --git a/hikari/impl/special_endpoints.py b/hikari/impl/special_endpoints.py
index e7432242..f760d735 100644
--- a/hikari/impl/special_endpoints.py
+++ b/hikari/impl/special_endpoints.py
@@ -68,7 +68,6 @@
 from hikari.interactions import base_interactions
 from hikari.internal import attrs_extensions
 from hikari.internal import data_binding
-from hikari.internal import deprecation
 from hikari.internal import mentions
 from hikari.internal import routes
 from hikari.internal import time
@@ -919,39 +918,11 @@ def build(self) -> typing.MutableMapping[str, typing.Any]:
 
 
 @attrs_extensions.with_copy
-@attrs.define(init=False, weakref_slot=False)
+@attrs.define(weakref_slot=False)
 class InteractionAutocompleteBuilder(special_endpoints.InteractionAutocompleteBuilder):
     """Standard implementation of `hikari.api.special_endpoints.InteractionAutocompleteBuilder`."""
 
-    _choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder] = attrs.field(factory=list)
-
-    def __init__(
-        self,
-        choices: typing.Union[
-            typing.Sequence[special_endpoints.AutocompleteChoiceBuilder], typing.Sequence[commands.CommandChoice]
-        ] = (),
-        *,
-        _stack_level: int = 0,
-    ) -> None:
-        new_choices: typing.List[special_endpoints.AutocompleteChoiceBuilder] = []
-        warned = False
-        for choice in choices:
-            if isinstance(choice, commands.CommandChoice):
-                if not warned:
-                    deprecation.warn_deprecated(
-                        "Passing CommandChoice",
-                        removal_version="2.0.0.dev119",
-                        additional_info="Use AutocompleteChoiceBuilder instead",
-                        quote=False,
-                        stack_level=3 + _stack_level,
-                    )
-                    warned = True
-
-                choice = AutocompleteChoiceBuilder(choice.name, choice.value)
-
-            new_choices.append(choice)
-
-        self.__attrs_init__(new_choices)
+    _choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder] = attrs.field(factory=tuple)
 
     @property
     def type(self) -> typing.Literal[base_interactions.ResponseType.AUTOCOMPLETE]:
@@ -961,39 +932,8 @@ def type(self) -> typing.Literal[base_interactions.ResponseType.AUTOCOMPLETE]:
     def choices(self) -> typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]:
         return self._choices
 
-    def set_choices(
-        self,
-        choices: typing.Union[
-            typing.Sequence[special_endpoints.AutocompleteChoiceBuilder], typing.Sequence[commands.CommandChoice]
-        ],
-        /,
-    ) -> Self:
-        """Set autocomplete choices.
-
-        Returns
-        -------
-        InteractionAutocompleteBuilder
-            Object of this builder.
-        """
-        real_choices: typing.List[special_endpoints.AutocompleteChoiceBuilder] = []
-        warned = False
-
-        for choice in choices:
-            if isinstance(choice, commands.CommandChoice):
-                if not warned:
-                    deprecation.warn_deprecated(
-                        "Passing CommandChoice",
-                        removal_version="2.0.0.dev119",
-                        additional_info="Use AutocompleteChoiceBuilder instead",
-                        quote=False,
-                    )
-                    warned = True
-
-                choice = AutocompleteChoiceBuilder(choice.name, choice.value)
-
-            real_choices.append(choice)
-
-        self._choices = real_choices
+    def set_choices(self, choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder], /) -> Self:
+        self._choices = choices
         return self
 
     def build(
@@ -1932,13 +1872,6 @@ def placeholder(self) -> undefined.UndefinedOr[str]:
     def value(self) -> undefined.UndefinedOr[str]:
         return self._value
 
-    @property
-    def required(self) -> bool:
-        deprecation.warn_deprecated(
-            ".required", removal_version="2.0.0.dev119", additional_info="Use .is_required", quote=False
-        )
-        return self._required
-
     @property
     def is_required(self) -> bool:
         return self._required
diff --git a/hikari/interactions/command_interactions.py b/hikari/interactions/command_interactions.py
index 99db3493..875c75f4 100644
--- a/hikari/interactions/command_interactions.py
+++ b/hikari/interactions/command_interactions.py
@@ -383,10 +383,7 @@ class AutocompleteInteraction(BaseCommandInteraction):
     """Parameter values provided by the user invoking this command."""
 
     def build_response(
-        self,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
+        self, choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
     ) -> special_endpoints.InteractionAutocompleteBuilder:
         """Get a message response builder for use in the REST server flow.
 
@@ -395,9 +392,10 @@ def build_response(
             `AutocompleteInteraction.create_response` should be used to set
             the interaction response.
 
-        .. deprecated:: 2.0.0.dev118
-            Passing `hikari.commands.CommandChoice`s here instead of
-            `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
+        Parameters
+        ----------
+        choices : typing.Sequence[hikari.api.special_endpoints.AutocompleteChoiceBuilder]
+            The choices for the autocomplete.
 
         Examples
         --------
@@ -420,18 +418,14 @@ async def handle_autocomplete_interaction(interaction: AutocompleteInteraction)
         hikari.api.special_endpoints.InteractionAutocompleteBuilder
             Interaction autocomplete response builder object.
         """
-        return self.app.rest.interaction_autocomplete_builder(choices, _stack_level=1)
-
-    async def create_response(
-        self,
-        choices: typing.Union[
-            typing.Sequence[commands.CommandChoice], typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]
-        ],
-    ) -> None:
+        return self.app.rest.interaction_autocomplete_builder(choices)
+
+    async def create_response(self, choices: typing.Sequence[special_endpoints.AutocompleteChoiceBuilder]) -> None:
         """Create a response for this autocomplete interaction.
 
-        .. deprecated:: 2.0.0.dev118
-            Passing `hikari.commands.CommandChoice`s here instead of
-            `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
+        Parameters
+        ----------
+        choices : typing.Sequence[hikari.api.special_endpoints.AutocompleteChoiceBuilder]
+            The choices for the autocomplete.
         """
-        await self.app.rest.create_autocomplete_response(self.id, self.token, choices, _stack_level=1)
+        await self.app.rest.create_autocomplete_response(self.id, self.token, choices)


Test patch:
diff --git a/tests/hikari/impl/test_special_endpoints.py b/tests/hikari/impl/test_special_endpoints.py
index 24a7601f..4eefd3bb 100644
--- a/tests/hikari/impl/test_special_endpoints.py
+++ b/tests/hikari/impl/test_special_endpoints.py
@@ -691,19 +691,6 @@ def test_choices(self):
             special_endpoints.AutocompleteChoiceBuilder(name="echo", value="charlie"),
         ]
 
-    def test_choices_for_deprecated_cmd_choices(self):
-        choices = [
-            commands.CommandChoice(name="meow", value="meow meow"),
-            commands.CommandChoice(name="name", value="x"),
-        ]
-
-        builder = special_endpoints.InteractionAutocompleteBuilder(choices)
-
-        assert builder.choices == [
-            special_endpoints.AutocompleteChoiceBuilder(name="meow", value="meow meow"),
-            special_endpoints.AutocompleteChoiceBuilder("name", "x"),
-        ]
-
     def test_set_choices(self):
         builder = special_endpoints.InteractionAutocompleteBuilder()
 
@@ -719,21 +706,6 @@ def test_set_choices(self):
             special_endpoints.AutocompleteChoiceBuilder("e", "a"),
         ]
 
-    def test_set_choices_for_deprecated_cmd_choices(self):
-        builder = special_endpoints.InteractionAutocompleteBuilder()
-
-        builder.set_choices(
-            [
-                commands.CommandChoice(name="its", value="the police!"),
-                commands.CommandChoice(name="inspect", value="me"),
-            ]
-        )
-
-        assert builder.choices == [
-            special_endpoints.AutocompleteChoiceBuilder("its", "the police!"),
-            special_endpoints.AutocompleteChoiceBuilder("inspect", "me"),
-        ]
-
     def test_build(self):
         builder = special_endpoints.InteractionAutocompleteBuilder(
             [
@@ -750,19 +722,6 @@ def test_build(self):
             "data": {"choices": [{"name": "meow", "value": "waaaa"}, {"name": "lotta", "value": "water"}]},
         }
 
-    def test_build_for_deprecated_cmd_choices(self):
-        builder = special_endpoints.InteractionAutocompleteBuilder(
-            [commands.CommandChoice(name="a", value="b"), commands.CommandChoice(name="c", value="d")]
-        )
-
-        data, files = builder.build(mock.Mock())
-
-        assert files == ()
-        assert data == {
-            "type": base_interactions.ResponseType.AUTOCOMPLETE,
-            "data": {"choices": [{"name": "a", "value": "b"}, {"name": "c", "value": "d"}]},
-        }
-
 
 class TestAutocompleteChoiceBuilder:
     def test_name_property(self):
@@ -1710,7 +1669,7 @@ def test_set_placeholder(self, text_input):
 
     def test_set_required(self, text_input):
         assert text_input.set_required(True) is text_input
-        assert text_input.required is True
+        assert text_input.is_required is True
 
     def test_set_value(self, text_input):
         assert text_input.set_value("valueeeee") is text_input
diff --git a/tests/hikari/interactions/test_command_interactions.py b/tests/hikari/interactions/test_command_interactions.py
index 523c218a..89321b3c 100644
--- a/tests/hikari/interactions/test_command_interactions.py
+++ b/tests/hikari/interactions/test_command_interactions.py
@@ -134,7 +134,7 @@ def test_build_response(self, mock_autocomplete_interaction, mock_app, mock_comm
         builder = mock_autocomplete_interaction.build_response(mock_command_choices)
 
         assert builder is mock_app.rest.interaction_autocomplete_builder.return_value
-        mock_app.rest.interaction_autocomplete_builder.assert_called_once_with(mock_command_choices, _stack_level=1)
+        mock_app.rest.interaction_autocomplete_builder.assert_called_once_with(mock_command_choices)
 
     @pytest.mark.asyncio()
     async def test_create_response(
@@ -146,5 +146,5 @@ async def test_create_response(
         await mock_autocomplete_interaction.create_response(mock_command_choices)
 
         mock_app.rest.create_autocomplete_response.assert_awaited_once_with(
-            2312312, "httptptptptptptptp", mock_command_choices, _stack_level=1
+            2312312, "httptptptptptptptp", mock_command_choices
         )