From ca4193cff4873959d2922e07c07412ad8f182f20 Mon Sep 17 00:00:00 2001 From: davfsa Date: Mon, 8 May 2023 11:30:46 +0200 Subject: [PATCH] Fix `messages` argument typing for `delete_messages` API (#1581) --- changes/1581.bugfix.md | 1 + hikari/api/rest.py | 9 +++++---- hikari/channels.py | 30 ++++++++++++++++-------------- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 changes/1581.bugfix.md diff --git a/changes/1581.bugfix.md b/changes/1581.bugfix.md new file mode 100644 index 0000000000..d9006db3e7 --- /dev/null +++ b/changes/1581.bugfix.md @@ -0,0 +1 @@ +Fix `messages` argument typing for `RESTClient.delete_messages`. diff --git a/hikari/api/rest.py b/hikari/api/rest.py index d276a98862..2675297887 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -1422,7 +1422,8 @@ async def delete_messages( channel: snowflakes.SnowflakeishOr[channels_.TextableChannel], messages: typing.Union[ snowflakes.SnowflakeishOr[messages_.PartialMessage], - snowflakes.SnowflakeishIterable[messages_.PartialMessage], + typing.Iterable[snowflakes.SnowflakeishOr[messages_.PartialMessage]], + typing.AsyncIterable[snowflakes.SnowflakeishOr[messages_.PartialMessage]], ], /, *other_messages: snowflakes.SnowflakeishOr[messages_.PartialMessage], @@ -1455,9 +1456,9 @@ async def delete_messages( channel : hikari.snowflakes.SnowflakeishOr[hikari.channels.TextableChannel] The channel to bulk delete the messages in. This may be the object or the ID of an existing channel. - messages : typing.Union[hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage], hikari.snowflakes.SnowflakeishIterable[hikari.messages.PartialMessage]] + messages Either the object/ID of an existing message to delete or an iterable - of the objects and/or IDs of existing messages to delete. + (sync or async) of the objects and/or IDs of existing messages to delete. Other Parameters ---------------- @@ -1471,7 +1472,7 @@ async def delete_messages( messages that were not removed. The `BaseException.__cause__` of the exception will be the original error that terminated this process. - """ # noqa: E501 - Line too long + """ @abc.abstractmethod async def add_reaction( diff --git a/hikari/channels.py b/hikari/channels.py index d1271d7db7..75d3cde6b6 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -79,7 +79,7 @@ from hikari import files from hikari import guilds from hikari import iterators - from hikari import messages + from hikari import messages as messages_ from hikari import stickers as stickers_ from hikari import users from hikari import voices @@ -409,7 +409,7 @@ def fetch_history( before: undefined.UndefinedOr[snowflakes.SearchableSnowflakeishOr[snowflakes.Unique]] = undefined.UNDEFINED, after: undefined.UndefinedOr[snowflakes.SearchableSnowflakeishOr[snowflakes.Unique]] = undefined.UNDEFINED, around: undefined.UndefinedOr[snowflakes.SearchableSnowflakeishOr[snowflakes.Unique]] = undefined.UNDEFINED, - ) -> iterators.LazyIterator[messages.Message]: + ) -> iterators.LazyIterator[messages_.Message]: """Browse the message history for a given text channel. .. note:: @@ -457,7 +457,7 @@ def fetch_history( """ return self.app.rest.fetch_messages(self.id, before=before, after=after, around=around) - async def fetch_message(self, message: snowflakes.SnowflakeishOr[messages.PartialMessage]) -> messages.Message: + async def fetch_message(self, message: snowflakes.SnowflakeishOr[messages_.PartialMessage]) -> messages_.Message: """Fetch a specific message in the given text channel. Parameters @@ -503,7 +503,7 @@ async def send( snowflakes.SnowflakeishSequence[stickers_.PartialSticker] ] = undefined.UNDEFINED, tts: undefined.UndefinedOr[bool] = undefined.UNDEFINED, - reply: undefined.UndefinedOr[snowflakes.SnowflakeishOr[messages.PartialMessage]] = undefined.UNDEFINED, + reply: undefined.UndefinedOr[snowflakes.SnowflakeishOr[messages_.PartialMessage]] = undefined.UNDEFINED, reply_must_exist: undefined.UndefinedOr[bool] = undefined.UNDEFINED, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, mentions_reply: undefined.UndefinedOr[bool] = undefined.UNDEFINED, @@ -513,8 +513,8 @@ async def send( role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds.PartialRole], bool] ] = undefined.UNDEFINED, - flags: typing.Union[undefined.UndefinedType, int, messages.MessageFlag] = undefined.UNDEFINED, - ) -> messages.Message: + flags: typing.Union[undefined.UndefinedType, int, messages_.MessageFlag] = undefined.UNDEFINED, + ) -> messages_.Message: """Create a message in this channel. Parameters @@ -699,7 +699,7 @@ def trigger_typing(self) -> special_endpoints.TypingIndicator: """ return self.app.rest.trigger_typing(self.id) - async def fetch_pins(self) -> typing.Sequence[messages.Message]: + async def fetch_pins(self) -> typing.Sequence[messages_.Message]: """Fetch the pinned messages in this text channel. Returns @@ -723,7 +723,7 @@ async def fetch_pins(self) -> typing.Sequence[messages.Message]: """ return await self.app.rest.fetch_pins(self.id) - async def pin_message(self, message: snowflakes.SnowflakeishOr[messages.PartialMessage]) -> None: + async def pin_message(self, message: snowflakes.SnowflakeishOr[messages_.PartialMessage]) -> None: """Pin an existing message in the text channel. Parameters @@ -749,7 +749,7 @@ async def pin_message(self, message: snowflakes.SnowflakeishOr[messages.PartialM """ return await self.app.rest.pin_message(self.id, message) - async def unpin_message(self, message: snowflakes.SnowflakeishOr[messages.PartialMessage]) -> None: + async def unpin_message(self, message: snowflakes.SnowflakeishOr[messages_.PartialMessage]) -> None: """Unpin a given message from the text channel. Parameters @@ -778,10 +778,12 @@ async def unpin_message(self, message: snowflakes.SnowflakeishOr[messages.Partia async def delete_messages( self, messages: typing.Union[ - snowflakes.SnowflakeishOr[messages.PartialMessage], snowflakes.SnowflakeishIterable[messages.PartialMessage] + snowflakes.SnowflakeishOr[messages_.PartialMessage], + typing.Iterable[snowflakes.SnowflakeishOr[messages_.PartialMessage]], + typing.AsyncIterable[snowflakes.SnowflakeishOr[messages_.PartialMessage]], ], /, - *other_messages: snowflakes.SnowflakeishOr[messages.PartialMessage], + *other_messages: snowflakes.SnowflakeishOr[messages_.PartialMessage], ) -> None: """Bulk-delete messages from the channel. @@ -808,9 +810,9 @@ async def delete_messages( Parameters ---------- - messages : typing.Union[hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage], hikari.snowflakes.SnowflakeishIterable[hikari.messages.PartialMessage]] + messages Either the object/ID of an existing message to delete or an iterable - of the objects and/or IDs of existing messages to delete. + (sync or async) of the objects and/or IDs of existing messages to delete. Other Parameters ---------------- @@ -824,7 +826,7 @@ async def delete_messages( messages that were not removed. The `BaseException.__cause__` of the exception will be the original error that terminated this process. - """ # noqa: E501 - Line too long + """ return await self.app.rest.delete_messages(self.id, messages, *other_messages)