From b3fdbc0333ed1a726914cf754603ba8e71dbcb22 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 20 May 2022 23:06:23 +0200 Subject: [PATCH 1/3] document empty lists --- telegram/_message.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index ea10c5dfd97..0e0f69afa4f 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -141,7 +141,7 @@ class Message(TelegramObject): entities (List[:class:`telegram.MessageEntity`], optional): For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See :attr:`parse_entity` and :attr:`parse_entities` methods for how to use properly. - caption_entities (List[:class:`telegram.MessageEntity`]): Optional. For Messages with a + caption_entities (List[:class:`telegram.MessageEntity`], optional): For messages with a Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See :attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities` methods for how to use properly. @@ -280,27 +280,29 @@ class Message(TelegramObject): media_group_id (:obj:`str`): Optional. The unique identifier of a media message group this message belongs to. text (:obj:`str`): Optional. The actual UTF-8 text of the message. - entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities like + entities (List[:class:`telegram.MessageEntity`]): Special entities like usernames, URLs, bot commands, etc. that appear in the text. See :attr:`Message.parse_entity` and :attr:`parse_entities` methods for how to use - properly. - caption_entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities like + properly. This list is empty if the message does not contain entities. + caption_entities (List[:class:`telegram.MessageEntity`]): Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See :attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities` methods for how - to use properly. + to use properly. This list is empty if the message does not contain caption entities. audio (:class:`telegram.Audio`): Optional. Information about the file. document (:class:`telegram.Document`): Optional. Information about the file. animation (:class:`telegram.Animation`) Optional. Information about the file. For backward compatibility, when this field is set, the document field will also be set. game (:class:`telegram.Game`): Optional. Information about the game. - photo (List[:class:`telegram.PhotoSize`]): Optional. Available sizes of the photo. + photo (List[:class:`telegram.PhotoSize`]): Available sizes of the photo. + This list is empty if the message does not contain a photo. sticker (:class:`telegram.Sticker`): Optional. Information about the sticker. video (:class:`telegram.Video`): Optional. Information about the video. voice (:class:`telegram.Voice`): Optional. Information about the file. video_note (:class:`telegram.VideoNote`): Optional. Information about the video message. - new_chat_members (List[:class:`telegram.User`]): Optional. Information about new members to - the chat. (the bot itself may be one of these members). + new_chat_members (List[:class:`telegram.User`]): Information about new members to + the chat. The bot itself may be one of these members. + This list is empty if the message does not contain new chat members. caption (:obj:`str`): Optional. Caption for the document, photo or video, 0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters. @@ -310,8 +312,8 @@ class Message(TelegramObject): left_chat_member (:class:`telegram.User`): Optional. Information about the user that left the group. (this member may be the bot itself). new_chat_title (:obj:`str`): Optional. A chat title was changed to this value. - new_chat_photo (List[:class:`telegram.PhotoSize`]): Optional. A chat photo was changed to - this value. + new_chat_photo (List[:class:`telegram.PhotoSize`]): A chat photo was changed to + this value. This list is empty if the message does not contain a new chat photo. delete_chat_photo (:obj:`bool`): Optional. The chat photo was deleted. group_chat_created (:obj:`bool`): Optional. The group has been created. supergroup_chat_created (:obj:`bool`): Optional. The supergroup has been created. @@ -2724,9 +2726,7 @@ def parse_entities(self, types: List[str] = None) -> Dict[MessageEntity, str]: types = MessageEntity.ALL_TYPES return { - entity: self.parse_entity(entity) - for entity in (self.entities or []) - if entity.type in types + entity: self.parse_entity(entity) for entity in self.entities if entity.type in types } def parse_caption_entities(self, types: List[str] = None) -> Dict[MessageEntity, str]: @@ -2757,7 +2757,7 @@ def parse_caption_entities(self, types: List[str] = None) -> Dict[MessageEntity, return { entity: self.parse_caption_entity(entity) - for entity in (self.caption_entities or []) + for entity in self.caption_entities if entity.type in types } From 1db66677bec055e07d0d1df4343400dbbbc584c9 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 20 May 2022 23:07:07 +0200 Subject: [PATCH 2/3] more --- telegram/_games/game.py | 5 +++-- telegram/_poll.py | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/telegram/_games/game.py b/telegram/_games/game.py index 995526039bc..00a774431db 100644 --- a/telegram/_games/game.py +++ b/telegram/_games/game.py @@ -63,8 +63,9 @@ class Game(TelegramObject): game message. Can be automatically edited to include current high scores for the game when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited using :meth:`telegram.Bot.edit_message_text`. - text_entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities that + text_entities (List[:class:`telegram.MessageEntity`]): Special entities that appear in text, such as usernames, URLs, bot commands, etc. + This list is empty if the message does not contain text entities. animation (:class:`telegram.Animation`): Optional. Animation that will be displayed in the game message in chats. Upload via `BotFather `_. @@ -182,7 +183,7 @@ def parse_text_entities(self, types: List[str] = None) -> Dict[MessageEntity, st return { entity: self.parse_text_entity(entity) - for entity in (self.text_entities or []) + for entity in self.text_entities if entity.type in types } diff --git a/telegram/_poll.py b/telegram/_poll.py index f48ae85d049..957af3afcfa 100644 --- a/telegram/_poll.py +++ b/telegram/_poll.py @@ -144,8 +144,12 @@ class Poll(TelegramObject): correct_option_id (:obj:`int`): Optional. Identifier of the correct answer option. explanation (:obj:`str`): Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll. - explanation_entities (List[:class:`telegram.MessageEntity`]): Optional. Special entities + explanation_entities (List[:class:`telegram.MessageEntity`]): Special entities like usernames, URLs, bot commands, etc. that appear in the :attr:`explanation`. + This list is empty if the message does not contain explanation entities. + + .. versionchanged:: 20.0 + This attribute is now always a (possibly empty) list and never :obj:`None`. open_period (:obj:`int`): Optional. Amount of time in seconds the poll will be active after creation. close_date (:obj:`datetime.datetime`): Optional. Point in time when the poll will be @@ -196,7 +200,7 @@ def __init__( self.allows_multiple_answers = allows_multiple_answers self.correct_option_id = correct_option_id self.explanation = explanation - self.explanation_entities = explanation_entities + self.explanation_entities = explanation_entities or [] self.open_period = open_period self.close_date = close_date @@ -283,7 +287,7 @@ def parse_explanation_entities(self, types: List[str] = None) -> Dict[MessageEnt return { entity: self.parse_explanation_entity(entity) - for entity in (self.explanation_entities or []) + for entity in self.explanation_entities if entity.type in types } From 51c6470581db9cc7d7e57cb7252661e8e2120ab3 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 26 May 2022 10:50:28 +0200 Subject: [PATCH 3/3] review --- telegram/_games/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/_games/game.py b/telegram/_games/game.py index 00a774431db..a17496147ed 100644 --- a/telegram/_games/game.py +++ b/telegram/_games/game.py @@ -63,7 +63,7 @@ class Game(TelegramObject): game message. Can be automatically edited to include current high scores for the game when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited using :meth:`telegram.Bot.edit_message_text`. - text_entities (List[:class:`telegram.MessageEntity`]): Special entities that + text_entities (List[:class:`telegram.MessageEntity`]): Special entities that appear in text, such as usernames, URLs, bot commands, etc. This list is empty if the message does not contain text entities. animation (:class:`telegram.Animation`): Optional. Animation that will be displayed in the