Skip to content

Commit

Permalink
Remove Optional from CommandInteraction.options (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude authored Jul 16, 2024
1 parent 4eb4042 commit 7cc7f3b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/1965.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `Optional` type hint from `CommandInteraction.options` - it will now always be an empty sequence when not provided.
4 changes: 1 addition & 3 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2532,9 +2532,7 @@ def deserialize_command_interaction(
if raw_guild_id := payload.get("guild_id"):
guild_id = snowflakes.Snowflake(raw_guild_id)

options: typing.Optional[typing.List[command_interactions.CommandInteractionOption]] = None
if raw_options := data_payload.get("options"):
options = [self._deserialize_interaction_command_option(option) for option in raw_options]
options = [self._deserialize_interaction_command_option(option) for option in data_payload.get("options", ())]

member: typing.Optional[base_interactions.InteractionMember]
if member_payload := payload.get("member"):
Expand Down
2 changes: 1 addition & 1 deletion hikari/interactions/command_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class CommandInteraction(
app_permissions: typing.Optional[permissions_.Permissions] = attrs.field(eq=False, hash=False, repr=False)
"""Permissions the bot has in this interaction's channel if it's in a guild."""

options: typing.Optional[typing.Sequence[CommandInteractionOption]] = attrs.field(eq=False, hash=False, repr=True)
options: typing.Sequence[CommandInteractionOption] = attrs.field(eq=False, hash=False, repr=True)
"""Parameter values provided by the user invoking this command."""

resolved: typing.Optional[base_interactions.ResolvedOptionData] = attrs.field(eq=False, hash=False, repr=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4538,7 +4538,7 @@ def test_deserialize_command_interaction_with_null_attributes(
assert interaction.guild_id is None
assert interaction.member is None
assert interaction.user == entity_factory_impl.deserialize_user(user_payload)
assert interaction.options is None
assert interaction.options == []
assert interaction.resolved is None
assert interaction.guild_locale is None
assert interaction.app_permissions is None
Expand Down

0 comments on commit 7cc7f3b

Please sign in to comment.