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
10 changes: 10 additions & 0 deletions changes/unreleased/5143.HYNP5H8WQXGydLcnAa2pkf.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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"]
closes_threads = ["5093"]
31 changes: 6 additions & 25 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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,
Expand Down
64 changes: 7 additions & 57 deletions src/telegram/_uniquegift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -340,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.

Expand Down Expand Up @@ -420,26 +417,20 @@ class UniqueGift(TelegramObject):

def __init__(
self,
gift_id: str,
base_name: str,
name: str,
number: int,
model: UniqueGiftModel,
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
Expand Down Expand Up @@ -486,6 +477,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
Expand All @@ -502,13 +496,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.
Expand Down Expand Up @@ -577,7 +564,6 @@ class UniqueGiftInfo(TelegramObject):
""":const:`telegram.constants.UniqueGiftInfoOrigin.UPGRADE`"""

__slots__ = (
"_last_resale_star_count",
"gift",
"last_resale_amount",
"last_resale_currency",
Expand All @@ -593,36 +579,19 @@ 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
self.origin: str = enum.get_member(constants.UniqueGiftInfoOrigin, origin, origin)
# 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
Expand All @@ -631,25 +600,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`."""
Expand Down
2 changes: 0 additions & 2 deletions src/telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
40 changes: 0 additions & 40 deletions tests/test_business_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import pytest

from telegram import (
Bot,
BusinessBotRights,
BusinessConnection,
Chat,
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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()

Expand Down
11 changes: 1 addition & 10 deletions tests/test_official/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}


Expand Down Expand Up @@ -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"},
}


Expand All @@ -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]:
Expand Down
Loading
Loading