Skip to content

Commit

Permalink
Remove deprecated functionality for 2.0.0.dev119 (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa committed Apr 2, 2023
1 parent ddb69fe commit 6d5d8a0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 191 deletions.
3 changes: 3 additions & 0 deletions changes/1580.breaking.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 4 additions & 16 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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]
Expand Down
18 changes: 5 additions & 13 deletions hikari/api/special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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:
Expand Down
32 changes: 4 additions & 28 deletions hikari/impl/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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], /
Expand Down Expand Up @@ -4066,34 +4061,15 @@ 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)

body = data_binding.JSONObjectBuilder()
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)
Expand Down
75 changes: 4 additions & 71 deletions hikari/impl/special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
32 changes: 13 additions & 19 deletions hikari/interactions/command_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
--------
Expand All @@ -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)
43 changes: 1 addition & 42 deletions tests/hikari/impl/test_special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
[
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/hikari/interactions/test_command_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)

0 comments on commit 6d5d8a0

Please sign in to comment.