Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions changes/unreleased/5078.FoNwUYLbXQFRebTFhR6UPn.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ Full Support for Bot API 9.3

.. warning::

Bot API 9.3 introduces a now required argument ``gift_id`` to ``UniqueGift``. For backward compatibility, the argument is currently still marked as optional in the signature and it's presence is enforced through a runtime check
In future versions, this argument will be made required in the signature as well.
Please make sure to update your code accordingly to avoid potential issues in the future. We recommend using keyword arguments when creating ``UniqueGift`` instances to ensure compatibility with future updates.
- Bot API 9.3 deprecates the argument ``exclude_limited`` of ``Bot.get_business_account_gifts`` in favor of the new arguments ``exclude_limited_upgradable`` and ``exclude_limited_non_upgradable``. The argument ``exclude_limited`` is still present in PTB for backward compatibility, but it will be removed in future releases. Please update your code accordingly.

- Bot API 9.3 introduces a now required argument ``gift_id`` to ``UniqueGift``. For backward compatibility, the argument is currently still marked as optional in the signature and it's presence is enforced through a runtime check. In future versions, this argument will be made required in the signature as well.
Please make sure to update your code accordingly to avoid potential issues in the future. We recommend using keyword arguments when creating ``UniqueGift`` instances to ensure compatibility with future updates.
"""

pull_requests = [
Expand All @@ -19,4 +20,5 @@ pull_requests = [
{ uid = "5090", author_uids = ["Bibo-Joshi"] },
{ uid = "5089", author_uids = ["Bibo-Joshi"] },
{ uid = "5092", author_uids = ["Bibo-Joshi"] },
{ uid = "5095", author_uids = ["Bibo-Joshi"] },
]
42 changes: 41 additions & 1 deletion src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@
TimePeriod,
)
from telegram._utils.warnings import warn
from telegram._utils.warnings_transition import build_deprecation_warning_message
from telegram._webhookinfo import WebhookInfo
from telegram.constants import InlineQueryLimit, ReactionEmoji
from telegram.error import EndPointNotFound, InvalidToken
from telegram.request import BaseRequest, RequestData
from telegram.request._httpxrequest import HTTPXRequest
from telegram.request._requestparameter import RequestParameter
from telegram.warnings import PTBUserWarning
from telegram.warnings import PTBDeprecationWarning, PTBUserWarning

if TYPE_CHECKING:
from telegram import (
Expand Down Expand Up @@ -9943,11 +9944,15 @@ async def get_business_account_gifts(
exclude_unsaved: bool | None = None,
exclude_saved: bool | None = None,
exclude_unlimited: bool | None = None,
# tags: deprecated NEXT.VERSION; bot api 9.3
exclude_limited: bool | None = None,
exclude_unique: bool | None = None,
sort_by_price: bool | None = None,
offset: str | None = None,
limit: int | None = None,
exclude_limited_upgradable: bool | None = None,
exclude_limited_non_upgradable: bool | None = None,
exclude_from_blockchain: bool | None = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand All @@ -9971,7 +9976,26 @@ async def get_business_account_gifts(
be purchased an unlimited number of times.
exclude_limited (:obj:`bool`, optional): Pass :obj:`True` to exclude gifts that can be
purchased a limited number of times.

.. depercated:: NEXT.VERSION
Bot API 9.3 deprecated this parameter in favor of
:paramref:`exclude_limited_upgradabale` and
:paramref:`exclude_limited_non_upgradable`.
exclude_limited_upgradable (:obj:`bool`, optional): Pass :obj:`True` to exclude gifts
that can be purchased a limited number of times and can be upgraded to unique.

.. versionadded:: NEXT.VERSION
exclude_limited_non_upgradable (:obj:`bool`, optional): Pass :obj:`True` to exclude
gifts that can be purchased a limited number of times and can't be upgraded to
unique

.. versionadded:: NEXT.VERSION
exclude_unique (:obj:`bool`, optional): Pass :obj:`True` to exclude unique gifts.
exclude_from_blockchain (:obj:`bool`, optional): Pass :obj:`True` to exclude gifts
that were assigned from the TON blockchain and can't be resold or transferred in
Telegram.

.. versionadded:: NEXT.VERSION
sort_by_price (:obj:`bool`, optional): Pass :obj:`True` to sort results by gift price
instead of send date. Sorting is applied before pagination.
offset (:obj:`str`, optional): Offset of the first entry to return as received from
Expand All @@ -9987,13 +10011,29 @@ async def get_business_account_gifts(
Raises:
:class:`telegram.error.TelegramError`
"""
if exclude_limited is not None:
self._warn(
PTBDeprecationWarning(
version="NEXT.VERSION",
message=build_deprecation_warning_message(
deprecated_name="exclude_limited",
new_name="exclude_limited_(non_)upgradable",
bot_api_version="9.3",
object_type="parameter",
),
),
stacklevel=2,
)
data: JSONDict = {
"business_connection_id": business_connection_id,
"exclude_unsaved": exclude_unsaved,
"exclude_saved": exclude_saved,
"exclude_unlimited": exclude_unlimited,
"exclude_limited": exclude_limited,
"exclude_limited_upgradable": exclude_limited_upgradable,
"exclude_limited_non_upgradable": exclude_limited_non_upgradable,
"exclude_unique": exclude_unique,
"exclude_from_blockchain": exclude_from_blockchain,
"sort_by_price": sort_by_price,
"offset": offset,
"limit": limit,
Expand Down
6 changes: 6 additions & 0 deletions src/telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4497,6 +4497,9 @@ async def get_business_account_gifts(
sort_by_price: bool | None = None,
offset: str | None = None,
limit: int | None = None,
exclude_limited_upgradable: bool | None = None,
exclude_limited_non_upgradable: bool | None = None,
exclude_from_blockchain: bool | None = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand All @@ -4511,7 +4514,10 @@ async def get_business_account_gifts(
exclude_saved=exclude_saved,
exclude_unlimited=exclude_unlimited,
exclude_limited=exclude_limited,
exclude_limited_upgradable=exclude_limited_upgradable,
exclude_limited_non_upgradable=exclude_limited_non_upgradable,
exclude_unique=exclude_unique,
exclude_from_blockchain=exclude_from_blockchain,
sort_by_price=sort_by_price,
offset=offset,
limit=limit,
Expand Down
44 changes: 44 additions & 0 deletions tests/test_business_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest

from telegram import (
Bot,
BusinessBotRights,
BusinessConnection,
Chat,
Expand All @@ -45,7 +46,10 @@
from telegram._utils.datetime import UTC
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram.constants import InputProfilePhotoType, InputStoryContentType
from telegram.ext import ExtBot
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.files import data_file
from tests.auxil.networking import OfflineRequest


class BusinessMethodsTestBase:
Expand Down Expand Up @@ -107,7 +111,10 @@ async def do_request_and_make_assertions(*args, **kwargs):
assert data.get("exclude_saved") is bool_param
assert data.get("exclude_unlimited") is bool_param
assert data.get("exclude_limited") is bool_param
assert data.get("exclude_limited_upgradable") is bool_param
assert data.get("exclude_limited_non_upgradable") is bool_param
assert data.get("exclude_unique") is bool_param
assert data.get("exclude_from_blockchain") is bool_param
assert data.get("sort_by_price") is bool_param
assert data.get("offset") == offset
assert data.get("limit") == limit
Expand All @@ -121,13 +128,50 @@ async def do_request_and_make_assertions(*args, **kwargs):
exclude_saved=bool_param,
exclude_unlimited=bool_param,
exclude_limited=bool_param,
exclude_limited_upgradable=bool_param,
exclude_limited_non_upgradable=bool_param,
exclude_unique=bool_param,
exclude_from_blockchain=bool_param,
sort_by_price=bool_param,
offset=offset,
limit=limit,
)
assert isinstance(obj, OwnedGifts)

@pytest.mark.parametrize("bot_class", [Bot, ExtBot])
async def test_get_business_account_gifts_exclude_limited_deprecation(
self, offline_bot, monkeypatch, bot_class
):
bot = bot_class(offline_bot.token, request=OfflineRequest())

async def dummy_response(*args, **kwargs):
return OwnedGifts(
total_count=1,
gifts=[
OwnedGiftRegular(
gift=Gift(
id="id1",
sticker=Sticker(
"file_id", "file_unique_id", 512, 512, False, False, "regular"
),
star_count=5,
),
send_date=dtm.datetime.now(tz=UTC).replace(microsecond=0),
owned_gift_id="some_id_1",
)
],
).to_dict()

monkeypatch.setattr(bot.request, "post", dummy_response)
with pytest.warns(PTBDeprecationWarning, match=r"9\.3.*exclude_limited") as record:
await bot.get_business_account_gifts(
business_connection_id=self.bci,
exclude_limited=True,
)

assert record[0].category == PTBDeprecationWarning
assert record[0].filename == __file__, "wrong stacklevel!"

async def test_get_business_account_star_balance(self, offline_bot, monkeypatch):
star_amount_json = StarAmount(amount=100, nanostar_amount=356).to_json()

Expand Down
Loading