From a58cfc81e85b53c183898602ea74646ab4169e78 Mon Sep 17 00:00:00 2001 From: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:24:45 +0300 Subject: [PATCH 1/4] add limits for `media` param of `Bot.send_media_group` to constants.py --- telegram/_bot.py | 8 +++++--- telegram/constants.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 35dc629bdb3..5721a391ef3 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -1828,9 +1828,11 @@ async def send_media_group( Args: chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| - media (List[:class:`telegram.InputMediaAudio`, :class:`telegram.InputMediaDocument`, \ - :class:`telegram.InputMediaPhoto`, :class:`telegram.InputMediaVideo`]): An array - describing messages to be sent, must include 2–10 items. + media (List[:class:`telegram.InputMediaAudio`, :class:`telegram.InputMediaDocument`,\ + :class:`telegram.InputMediaPhoto`, :class:`telegram.InputMediaVideo`]): + An array describing messages to be sent, must include + :tg-const:`telegram.constants.MediaGroupLimit.MIN_MEDIA_LENGTH`– + :tg-const:`telegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTH` items. disable_notification (:obj:`bool`, optional): |disable_notification| protect_content (:obj:`bool`, optional): |protect_content| diff --git a/telegram/constants.py b/telegram/constants.py index cf3f033ad1d..417975b673e 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -61,6 +61,7 @@ "InvoiceLimit", "LocationLimit", "MaskPosition", + "MediaGroupLimit", "MenuButtonType", "MessageAttachmentType", "MessageEntityType", @@ -919,6 +920,27 @@ class MaskPosition(StringEnum): """:obj:`str`: Mask position for a sticker on the chin.""" +class MediaGroupLimit(IntEnum): + """This enum contains limitations for :meth:`telegram.Bot.send_media_group`. + The enum members of this enumeration are instances of :class:`int` and can be treated as such. + + .. versionadded:: 20.0 + """ + + __slots__ = () + + MIN_MEDIA_LENGTH = 2 + """:obj:`int`: Minimum length of a :obj:`list` passed as the + :paramref:`~telegram.Bot.send_media_group.media` parameter of + :meth:`telegram.Bot.send_media_group`. + """ + MAX_MEDIA_LENGTH = 10 + """:obj:`int`: Minimum length of a :obj:`list` passed as the + :paramref:`~telegram.Bot.send_media_group.media` parameter of + :meth:`telegram.Bot.send_media_group`. + """ + + class MenuButtonType(StringEnum): """This enum contains the available types of :class:`telegram.MenuButton`. The enum members of this enumeration are instances of :class:`str` and can be treated as such. From 318b8914e62bc6dc11eb43eacf6f0ba440d1f7d2 Mon Sep 17 00:00:00 2001 From: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:41:51 +0300 Subject: [PATCH 2/4] add limit for `suggested_tip_amounts`, fix docstr of `InvoiceLimit` --- telegram/_bot.py | 15 +++++++++------ telegram/_payment/invoice.py | 5 +++++ telegram/constants.py | 13 +++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 5721a391ef3..41fd7d8cd3f 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -4168,9 +4168,9 @@ async def send_invoice( .. versionadded:: 13.5 suggested_tip_amounts (List[:obj:`int`], optional): An array of suggested amounts of tips in the *smallest* units of the currency (integer, **not** - float/double). At most 4 suggested tip amounts can be specified. The suggested tip - amounts must be positive, passed in a strictly increased order and must not exceed - :paramref:`max_tip_amount`. + float/double). At most :tg-const:`telegram.Invoice.MAX_TIP_AMOUNTS` suggested tip + amounts can be specified. The suggested tip amounts must be positive, passed in a + strictly increased order and must not exceed :paramref:`max_tip_amount`. .. versionadded:: 13.5 start_parameter (:obj:`str`, optional): Unique deep-linking parameter. If left empty, @@ -6693,9 +6693,12 @@ async def create_invoice_link( majority of currencies). Defaults to ``0``. suggested_tip_amounts (List[:obj:`int`], optional): An array of suggested amounts of tips in the *smallest* units of the currency (integer, **not** - float/double). At most 4 suggested tip amounts can be specified. The suggested tip - amounts must be positive, passed in a strictly increased order and must not exceed - :paramref:`max_tip_amount`. + float/double). At most :tg-const:`telegram.Invoice.MAX_TIP_AMOUNTS` suggested tip + amounts can be specified. The suggested tip amounts must be positive, passed in a + strictly increased order and must not exceed :paramref:`max_tip_amount`. + + .. versionchanged:: 20.0 + Accept :obj:`Sequence` instead of :obj:`List`. provider_data (:obj:`str` | :obj:`object`, optional): Data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is diff --git a/telegram/_payment/invoice.py b/telegram/_payment/invoice.py index 22bc17e7abe..2c33e1fdc68 100644 --- a/telegram/_payment/invoice.py +++ b/telegram/_payment/invoice.py @@ -119,3 +119,8 @@ def __init__( .. versionadded:: 20.0 """ + MAX_TIP_AMOUNTS: ClassVar[int] = constants.InvoiceLimit.MAX_TIP_AMOUNTS + """:const:`telegram.constants.InvoiceLimit.MAX_TIP_AMOUNTS` + + .. versionadded:: 20.0 + """ diff --git a/telegram/constants.py b/telegram/constants.py index 417975b673e..40c54aeb8f1 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -1425,8 +1425,9 @@ class UpdateType(StringEnum): class InvoiceLimit(IntEnum): - """This enum contains limitations for :meth:`telegram.Bot.create_invoice_link`. The enum - members of this enumeration are instances of :class:`int` and can be treated as such. + """This enum contains limitations for :class:`telegram.InputInvoiceMessageContent`, + :meth:`telegram.Bot.send_invoice`, and :meth:`telegram.Bot.create_invoice_link`. + The enum members of this enumeration are instances of :class:`int` and can be treated as such. .. versionadded:: 20.0 """ @@ -1493,6 +1494,14 @@ class InvoiceLimit(IntEnum): * :paramref:`~telegram.Bot.create_invoice_link.payload` parameter of :meth:`telegram.Bot.create_invoice_link`. """ + MAX_TIP_AMOUNTS = 4 + """:obj:`int`: Maximum length of a :obj:`Sequence` passed as: + + * :paramref:`~telegram.Bot.send_invoice.suggested_tip_amounts` parameter of + :meth:`telegram.Bot.send_invoice`. + * :paramref:`~telegram.Bot.create_invoice_link.suggested_tip_amounts` parameter of + :meth:`telegram.Bot.create_invoice_link`. + """ class UserProfilePhotosLimit(IntEnum): From 4332872ecd01b830bee9b0be2fb56b067f122873 Mon Sep 17 00:00:00 2001 From: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:39:41 +0300 Subject: [PATCH 3/4] fix: remove `versionadded` it is supposed to be in #3412 only --- telegram/_bot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/telegram/_bot.py b/telegram/_bot.py index 41fd7d8cd3f..35d35ef2a7b 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -6696,9 +6696,6 @@ async def create_invoice_link( float/double). At most :tg-const:`telegram.Invoice.MAX_TIP_AMOUNTS` suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed :paramref:`max_tip_amount`. - - .. versionchanged:: 20.0 - Accept :obj:`Sequence` instead of :obj:`List`. provider_data (:obj:`str` | :obj:`object`, optional): Data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is From 2967cd6cb255c9f3afbabe6bc14906b37ec5dfce Mon Sep 17 00:00:00 2001 From: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com> Date: Fri, 30 Dec 2022 00:13:51 +0300 Subject: [PATCH 4/4] fix docstr of `MAX_MEDIA_LENGTH` --- telegram/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/constants.py b/telegram/constants.py index 40c54aeb8f1..3fae673e0d0 100644 --- a/telegram/constants.py +++ b/telegram/constants.py @@ -935,7 +935,7 @@ class MediaGroupLimit(IntEnum): :meth:`telegram.Bot.send_media_group`. """ MAX_MEDIA_LENGTH = 10 - """:obj:`int`: Minimum length of a :obj:`list` passed as the + """:obj:`int`: Maximum length of a :obj:`list` passed as the :paramref:`~telegram.Bot.send_media_group.media` parameter of :meth:`telegram.Bot.send_media_group`. """