From 3260f7e16219456c43f705d9b2925809c08a483e Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Thu, 19 Feb 2026 12:21:55 -0500 Subject: [PATCH 1/3] Remove things deprecated by Bot API 9.3 --- src/telegram/_bot.py | 31 +++------------- src/telegram/_uniquegift.py | 61 ++----------------------------- src/telegram/ext/_extbot.py | 2 - tests/test_business_methods.py | 40 -------------------- tests/test_official/exceptions.py | 11 +----- tests/test_uniquegift.py | 37 ------------------- 6 files changed, 11 insertions(+), 171 deletions(-) diff --git a/src/telegram/_bot.py b/src/telegram/_bot.py index f0a8cfd6aa8..9b014570cee 100644 --- a/src/telegram/_bot.py +++ b/src/telegram/_bot.py @@ -106,14 +106,13 @@ 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 PTBDeprecationWarning, PTBUserWarning +from telegram.warnings import PTBUserWarning if TYPE_CHECKING: from telegram import ( @@ -9942,8 +9941,6 @@ async def get_business_account_gifts( exclude_unsaved: bool | None = None, exclude_saved: bool | None = None, exclude_unlimited: bool | None = None, - # tags: deprecated 22.6; bot api 9.3 - exclude_limited: bool | None = None, exclude_unique: bool | None = None, sort_by_price: bool | None = None, offset: str | None = None, @@ -9964,6 +9961,11 @@ async def get_business_account_gifts( .. versionadded:: 22.1 + .. versionremoved:: NEXT.VERSION + Bot API 9.3 removed the :paramref:`exclude_limited` parameter. Use + :paramref:`exclude_limited_upgradable` and :paramref:`exclude_limited_non_upgradable` + instead. + Args: business_connection_id (:obj:`str`): Unique identifier of the business connection. exclude_unsaved (:obj:`bool`, optional): Pass :obj:`True` to exclude gifts that aren't @@ -9972,13 +9974,6 @@ async def get_business_account_gifts( to the account's profile page. exclude_unlimited (:obj:`bool`, optional): Pass :obj:`True` to exclude gifts that can 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. - - .. deprecated:: 22.6 - 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. @@ -10009,25 +10004,11 @@ async def get_business_account_gifts( Raises: :class:`telegram.error.TelegramError` """ - if exclude_limited is not None: - self._warn( - PTBDeprecationWarning( - version="22.6", - 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, diff --git a/src/telegram/_uniquegift.py b/src/telegram/_uniquegift.py index 56fe64e37af..7c2fb16a948 100644 --- a/src/telegram/_uniquegift.py +++ b/src/telegram/_uniquegift.py @@ -31,12 +31,6 @@ from telegram._utils.argumentparsing import de_json_optional, parse_sequence_arg from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp from telegram._utils.types import JSONDict -from telegram._utils.warnings import warn -from telegram._utils.warnings_transition import ( - build_deprecation_warning_message, - warn_about_deprecated_attr_in_property, -) -from telegram.warnings import PTBDeprecationWarning if TYPE_CHECKING: from telegram import Bot @@ -420,6 +414,7 @@ class UniqueGift(TelegramObject): def __init__( self, + gift_id: str, base_name: str, name: str, number: int, @@ -427,19 +422,12 @@ def __init__( symbol: UniqueGiftSymbol, backdrop: UniqueGiftBackdrop, publisher_chat: Chat | None = None, - # tags: deprecated 22.6, bot api 9.3 - # temporarily optional to account for changed signature - gift_id: str | None = None, is_from_blockchain: bool | None = None, is_premium: bool | None = None, colors: UniqueGiftColors | None = None, *, api_kwargs: JSONDict | None = None, ): - # tags: deprecated 22.6, bot api 9.3 - if gift_id is None: - raise TypeError("`gift_id` is a required argument since Bot API 9.3") - super().__init__(api_kwargs=api_kwargs) self.gift_id: str = gift_id self.base_name: str = base_name @@ -486,6 +474,9 @@ class UniqueGiftInfo(TelegramObject): .. versionadded:: 22.1 + .. versionremoved:: NEXT.VERSION + Removed argument and attribute ``last_resale_star_count`` deprecated since Bot API 9.3. + Args: gift (:class:`UniqueGift`): Information about the gift. origin (:obj:`str`): Origin of the gift. Currently, either :attr:`UPGRADE` for gifts @@ -502,13 +493,6 @@ class UniqueGiftInfo(TelegramObject): bot; only present for gifts received on behalf of business accounts. transfer_star_count (:obj:`int`, optional): Number of Telegram Stars that must be paid to transfer the gift; omitted if the bot cannot transfer the gift. - last_resale_star_count (:obj:`int`, optional): For gifts bought from other users, the price - paid for the gift. - - .. versionadded:: 22.3 - .. deprecated:: 22.6 - Bot API 9.3 deprecated this field. Use :attr:`last_resale_currency` and - :attr:`last_resale_amount` instead. last_resale_currency (:obj:`str`, optional): For gifts bought from other users, the currency in which the payment for the gift was done. Currently, one of ``XTR`` for Telegram Stars or ``TON`` for toncoins. @@ -577,7 +561,6 @@ class UniqueGiftInfo(TelegramObject): """:const:`telegram.constants.UniqueGiftInfoOrigin.UPGRADE`""" __slots__ = ( - "_last_resale_star_count", "gift", "last_resale_amount", "last_resale_currency", @@ -593,28 +576,12 @@ def __init__( origin: str, owned_gift_id: str | None = None, transfer_star_count: int | None = None, - # tags: deprecated 22.6; bot api 9.3 - last_resale_star_count: int | None = None, next_transfer_date: dtm.datetime | None = None, last_resale_currency: str | None = None, last_resale_amount: int | None = None, *, api_kwargs: JSONDict | None = None, ): - if last_resale_star_count is not None: - warn( - PTBDeprecationWarning( - version="22.6", - message=build_deprecation_warning_message( - deprecated_name="last_resale_star_count", - new_name="last_resale_currency/amount", - bot_api_version="9.3", - object_type="parameter", - ), - ), - stacklevel=2, - ) - super().__init__(api_kwargs=api_kwargs) # Required self.gift: UniqueGift = gift @@ -622,7 +589,6 @@ def __init__( # Optional self.owned_gift_id: str | None = owned_gift_id self.transfer_star_count: int | None = transfer_star_count - self._last_resale_star_count: int | None = last_resale_star_count self.next_transfer_date: dtm.datetime | None = next_transfer_date self.last_resale_currency: str | None = last_resale_currency self.last_resale_amount: int | None = last_resale_amount @@ -631,25 +597,6 @@ def __init__( self._freeze() - # tags: deprecated 22.6; bot api 9.3 - @property - def last_resale_star_count(self) -> int | None: - """:obj:`int`: Optional. For gifts bought from other users, the price - paid for the gift. - - .. versionadded:: 22.3 - .. deprecated:: 22.6 - Bot API 9.3 deprecated this field. Use :attr:`last_resale_currency` and - :attr:`last_resale_amount` instead. - """ - warn_about_deprecated_attr_in_property( - deprecated_attr_name="last_resale_star_count", - new_attr_name="last_resale_currency/amount", - bot_api_version="9.3", - ptb_version="22.6", - ) - return self._last_resale_star_count - @classmethod def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGiftInfo": """See :meth:`telegram.TelegramObject.de_json`.""" diff --git a/src/telegram/ext/_extbot.py b/src/telegram/ext/_extbot.py index 15c84b4ce03..c2407a1cb49 100644 --- a/src/telegram/ext/_extbot.py +++ b/src/telegram/ext/_extbot.py @@ -4492,7 +4492,6 @@ async def get_business_account_gifts( exclude_unsaved: bool | None = None, exclude_saved: bool | None = None, exclude_unlimited: bool | None = None, - exclude_limited: bool | None = None, exclude_unique: bool | None = None, sort_by_price: bool | None = None, offset: str | None = None, @@ -4513,7 +4512,6 @@ async def get_business_account_gifts( 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, diff --git a/tests/test_business_methods.py b/tests/test_business_methods.py index 243bd753799..43a666eb07e 100644 --- a/tests/test_business_methods.py +++ b/tests/test_business_methods.py @@ -21,7 +21,6 @@ import pytest from telegram import ( - Bot, BusinessBotRights, BusinessConnection, Chat, @@ -46,10 +45,7 @@ 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: @@ -110,7 +106,6 @@ async def do_request_and_make_assertions(*args, **kwargs): assert data.get("exclude_unsaved") is bool_param 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 @@ -127,7 +122,6 @@ async def do_request_and_make_assertions(*args, **kwargs): exclude_unsaved=bool_param, 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, @@ -138,40 +132,6 @@ async def do_request_and_make_assertions(*args, **kwargs): ) 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() diff --git a/tests/test_official/exceptions.py b/tests/test_official/exceptions.py index bfc1f065374..1f7a86f0ebc 100644 --- a/tests/test_official/exceptions.py +++ b/tests/test_official/exceptions.py @@ -159,9 +159,6 @@ class ParamTypeCheckingExceptions: "InputStoryContent": {"type"}, # attributes common to all subclasses "StoryAreaType": {"type"}, # attributes common to all subclasses "InputProfilePhoto": {"type"}, # attributes common to all subclasses - # backwards compatibility for api 9.3 changes - # tags: deprecated 22.6, bot api 9.3 - "UniqueGiftInfo": {"last_resale_star_count"}, } @@ -209,9 +206,6 @@ def ptb_ignored_params(object_name: str) -> set[str]: "send_venue": {"latitude", "longitude", "title", "address"}, "send_contact": {"phone_number", "first_name"}, # ----> - # backwards compatibility for api 9.3 changes - # tags: deprecated 22.6, bot api 9.3 - "UniqueGift": {"gift_id"}, } @@ -220,10 +214,7 @@ def ignored_param_requirements(object_name: str) -> set[str]: # Arguments that are optional arguments for now for backwards compatibility -BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = { - # tags: deprecated 22.6, bot api 9.3 - "get_business_account_gifts": {"exclude_limited"}, -} +BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {} def backwards_compat_kwargs(object_name: str) -> set[str]: diff --git a/tests/test_uniquegift.py b/tests/test_uniquegift.py index a61a4da2183..0ea8049435f 100644 --- a/tests/test_uniquegift.py +++ b/tests/test_uniquegift.py @@ -35,7 +35,6 @@ ) from telegram._utils.datetime import UTC, to_timestamp from telegram.constants import UniqueGiftInfoOrigin -from telegram.warnings import PTBDeprecationWarning from tests.auxil.slots import mro_slots @@ -258,19 +257,6 @@ def test_equality(self, unique_gift): assert a != d assert hash(a) != hash(d) - def test_gift_id_required_workaround(self): - # tags: deprecated 22.6, bot api 9.3 - with pytest.raises(TypeError, match="`gift_id` is a required"): - UniqueGift( - base_name=self.base_name, - name=self.name, - number=self.number, - model=self.model, - symbol=self.symbol, - backdrop=self.backdrop, - publisher_chat=self.publisher_chat, - ) - @pytest.fixture def unique_gift_model(): @@ -524,7 +510,6 @@ def unique_gift_info(): origin=UniqueGiftInfoTestBase.origin, owned_gift_id=UniqueGiftInfoTestBase.owned_gift_id, transfer_star_count=UniqueGiftInfoTestBase.transfer_star_count, - last_resale_star_count=UniqueGiftInfoTestBase.last_resale_star_count, last_resale_currency=UniqueGiftInfoTestBase.last_resale_currency, last_resale_amount=UniqueGiftInfoTestBase.last_resale_amount, next_transfer_date=UniqueGiftInfoTestBase.next_transfer_date, @@ -556,7 +541,6 @@ class UniqueGiftInfoTestBase: origin = UniqueGiftInfo.UPGRADE owned_gift_id = "some_id" transfer_star_count = 10 - last_resale_star_count = 5 last_resale_currency = "XTR" last_resale_amount = 1234 next_transfer_date = dtm.datetime.now(tz=UTC).replace(microsecond=0) @@ -576,7 +560,6 @@ def test_de_json(self, offline_bot): "origin": self.origin, "owned_gift_id": self.owned_gift_id, "transfer_star_count": self.transfer_star_count, - "last_resale_star_count": self.last_resale_star_count, "last_resale_currency": self.last_resale_currency, "last_resale_amount": self.last_resale_amount, "next_transfer_date": to_timestamp(self.next_transfer_date), @@ -587,7 +570,6 @@ def test_de_json(self, offline_bot): assert unique_gift_info.origin == self.origin assert unique_gift_info.owned_gift_id == self.owned_gift_id assert unique_gift_info.transfer_star_count == self.transfer_star_count - assert unique_gift_info.last_resale_star_count == self.last_resale_star_count assert unique_gift_info.last_resale_currency == self.last_resale_currency assert unique_gift_info.last_resale_amount == self.last_resale_amount assert unique_gift_info.next_transfer_date == self.next_transfer_date @@ -598,7 +580,6 @@ def test_de_json_localization(self, tz_bot, offline_bot, raw_bot): "origin": self.origin, "owned_gift_id": self.owned_gift_id, "transfer_star_count": self.transfer_star_count, - "last_resale_star_count": self.last_resale_star_count, "last_resale_currency": self.last_resale_currency, "last_resale_amount": self.last_resale_amount, "next_transfer_date": to_timestamp(self.next_transfer_date), @@ -648,21 +629,3 @@ def test_equality(self, unique_gift_info): assert a != d assert hash(a) != hash(d) - - def test_last_resale_star_count_argument_deprecation(self): - with pytest.warns(PTBDeprecationWarning, match=r"9\.3.*last_resale_star_count") as record: - UniqueGiftInfo( - gift=self.gift, - origin=UniqueGiftInfo.TRANSFER, - last_resale_star_count=self.last_resale_star_count, - ) - - assert record[0].category == PTBDeprecationWarning - assert record[0].filename == __file__, "wrong stacklevel!" - - def test_last_resale_star_count_attribute_deprecation(self, unique_gift_info): - with pytest.warns(PTBDeprecationWarning, match=r"9\.3.*last_resale_star_count") as record: - assert unique_gift_info.last_resale_star_count == self.last_resale_star_count - - assert record[0].category == PTBDeprecationWarning - assert record[0].filename == __file__, "wrong stacklevel!" From f2fe57de14ca9ec928d43f5a6538537e4778162c Mon Sep 17 00:00:00 2001 From: harshil21 <37377066+harshil21@users.noreply.github.com> Date: Thu, 19 Feb 2026 17:24:28 +0000 Subject: [PATCH 2/3] Add chango fragment for PR #5143 --- changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml diff --git a/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml b/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml new file mode 100644 index 00000000000..39e76be3dd9 --- /dev/null +++ b/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml @@ -0,0 +1,6 @@ +breaking = "Remove Functionality Deprecated in Bot API 9.3" +features = "Remove Functionality Deprecated in Bot API 9.3" +[[pull_requests]] +uid = "5143" +author_uids = ["harshil21"] +closes_threads = ["5093"] From 36be94a6c0aff31ca8c96a819b20f55997f9deaf Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Tue, 24 Feb 2026 12:52:06 -0500 Subject: [PATCH 3/3] Review: Changelog and versionchanged --- changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml | 8 ++++++-- src/telegram/_uniquegift.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml b/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml index 39e76be3dd9..516f53f6aee 100644 --- a/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml +++ b/changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml @@ -1,5 +1,9 @@ -breaking = "Remove Functionality Deprecated in Bot API 9.3" -features = "Remove Functionality Deprecated in Bot API 9.3" +breaking = """Remove Functionality Deprecated in Bot API 9.3 + +* Remove deprecated argument and attribute ``UniqueGiftInfo.last_resale_star_count``. +* Remove deprecated argument and attribute ``Bot.get_business_account_gifts.exclude_limited``. +* :attr:`telegram.UniqueGift.gift_id` is now a positional argument. +""" [[pull_requests]] uid = "5143" author_uids = ["harshil21"] diff --git a/src/telegram/_uniquegift.py b/src/telegram/_uniquegift.py index 7c2fb16a948..b6b92b654ce 100644 --- a/src/telegram/_uniquegift.py +++ b/src/telegram/_uniquegift.py @@ -334,6 +334,9 @@ class UniqueGift(TelegramObject): .. versionadded:: 22.1 + .. versionchanged:: NEXT.VERSION + :attr:`gift_id` is now a positional argument. + Args: gift_id (:obj:`str`): Identifier of the regular gift from which the gift was upgraded.