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
11 changes: 11 additions & 0 deletions changes/unreleased/4852.mz3RDjX636ZdGoR456C6v9.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
breaking = """Remove Functionality Deprecated in API 9.0

* Remove deprecated argument and attribute ``BusinessConnection.can_reply``.
* Remove deprecated argument and attribute ``ChatFullInfo.can_send_gift``
* Remove deprecated class ``constants.StarTransactions``. Please instead use :attr:`telegram.constants.Nanostar.VALUE`.
* Remove deprecated attributes ``constants.StarTransactionsLimit.NANOSTAR_MIN_AMOUNT`` and ``constants.StarTransactionsLimit.NANOSTAR_MAX_AMOUNT``. Please instead use :attr:`telegram.constants.NanostarLimit.MIN_AMOUNT` and :attr:`telegram.constants.NanostarLimit.MAX_AMOUNT`.
"""
[[pull_requests]]
uid = "4852"
author_uid = "aelkheir"
closes_threads = []
56 changes: 5 additions & 51 deletions src/telegram/_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
from telegram._utils.argumentparsing import de_json_optional, de_list_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 @@ -195,19 +189,17 @@ class BusinessConnection(TelegramObject):

.. versionadded:: 21.1
.. versionchanged:: 22.1
Equality comparison now considers :attr:`rights` instead of :attr:`can_reply`.
Equality comparison now considers :attr:`rights` instead of ``can_reply``.

.. versionremoved:: NEXT.VERSION
Removed argument and attribute ``can_reply`` deprecated by API 9.0.

Args:
id (:obj:`str`): Unique identifier of the business connection.
user (:class:`telegram.User`): Business account user that created the business connection.
user_chat_id (:obj:`int`): Identifier of a private chat with the user who created the
business connection.
date (:obj:`datetime.datetime`): Date the connection was established in Unix time.
can_reply (:obj:`bool`, optional): True, if the bot can act on behalf of the business
account in chats that were active in the last 24 hours.

.. deprecated:: 22.1
Bot API 9.0 deprecated this argument in favor of :paramref:`rights`.
is_enabled (:obj:`bool`): True, if the connection is active.
rights (:class:`BusinessBotRights`, optional): Rights of the business bot.

Expand All @@ -226,7 +218,6 @@ class BusinessConnection(TelegramObject):
"""

__slots__ = (
"_can_reply",
"date",
"id",
"is_enabled",
Expand All @@ -241,37 +232,16 @@ def __init__(
user: "User",
user_chat_id: int,
date: dtm.datetime,
can_reply: Optional[bool] = None,
# temporarily optional to account for changed signature
# tags: deprecated 22.1; bot api 9.0
is_enabled: Optional[bool] = None,
is_enabled: bool,
rights: Optional[BusinessBotRights] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
if is_enabled is None:
raise TypeError("Missing required argument `is_enabled`")

if can_reply is not None:
warn(
PTBDeprecationWarning(
version="22.1",
message=build_deprecation_warning_message(
deprecated_name="can_reply",
new_name="rights",
bot_api_version="9.0",
object_type="parameter",
),
),
stacklevel=2,
)

super().__init__(api_kwargs=api_kwargs)
self.id: str = id
self.user: User = user
self.user_chat_id: int = user_chat_id
self.date: dtm.datetime = date
self._can_reply: Optional[bool] = can_reply
self.is_enabled: bool = is_enabled
self.rights: Optional[BusinessBotRights] = rights

Expand All @@ -286,22 +256,6 @@ def __init__(

self._freeze()

@property
def can_reply(self) -> Optional[bool]:
""":obj:`bool`: Optional. True, if the bot can act on behalf of the business account in
chats that were active in the last 24 hours.

.. deprecated:: 22.1
Bot API 9.0 deprecated this argument in favor of :attr:`rights`
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="can_reply",
new_attr_name="rights",
bot_api_version="9.0",
ptb_version="22.1",
)
return self._can_reply

@classmethod
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "BusinessConnection":
"""See :meth:`telegram.TelegramObject.de_json`."""
Expand Down
59 changes: 4 additions & 55 deletions src/telegram/_chatfullinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
get_timedelta_value,
)
from telegram._utils.types import JSONDict, TimePeriod
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, BusinessIntro, BusinessLocation, BusinessOpeningHours, Message
Expand All @@ -66,6 +60,9 @@ class ChatFullInfo(_ChatBase):
object. Previously those were only available because this class inherited from
:class:`telegram.Chat`.

.. versionremoved:: NEXT.VERSION
Removed argument and attribute ``can_send_gift`` deprecated by API 9.0.

Args:
id (:obj:`int`): Unique identifier for this chat.
type (:obj:`str`): Type of chat, can be either :attr:`PRIVATE`, :attr:`GROUP`,
Expand Down Expand Up @@ -226,13 +223,6 @@ class ChatFullInfo(_ChatBase):
sent or forwarded to the channel chat. The field is available only for channel chats.

.. versionadded:: 21.4
can_send_gift (:obj:`bool`, optional): :obj:`True`, if gifts can be sent to the chat.

.. versionadded:: 21.11

.. deprecated:: 22.1
Bot API 9.0 introduced :paramref:`accepted_gift_types`, replacing this argument.
Hence, this argument will be removed in future versions.

Attributes:
id (:obj:`int`): Unique identifier for this chat.
Expand Down Expand Up @@ -403,7 +393,6 @@ class ChatFullInfo(_ChatBase):
"""

__slots__ = (
"_can_send_gift",
"_message_auto_delete_time",
"_slow_mode_delay",
"accent_color_id",
Expand Down Expand Up @@ -450,6 +439,7 @@ def __init__(
type: str,
accent_color_id: int,
max_reaction_count: int,
accepted_gift_types: AcceptedGiftTypes,
title: Optional[str] = None,
username: Optional[str] = None,
first_name: Optional[str] = None,
Expand Down Expand Up @@ -490,10 +480,6 @@ def __init__(
linked_chat_id: Optional[int] = None,
location: Optional[ChatLocation] = None,
can_send_paid_media: Optional[bool] = None,
# tags: deprecated 22.1; bot api 9.0
can_send_gift: Optional[bool] = None,
# temporarily optional to account for changed signature
accepted_gift_types: Optional[AcceptedGiftTypes] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
Expand All @@ -507,23 +493,6 @@ def __init__(
is_forum=is_forum,
api_kwargs=api_kwargs,
)
if accepted_gift_types is None:
raise TypeError("`accepted_gift_type` is a required argument since Bot API 9.0")

if can_send_gift is not None:
warn(
PTBDeprecationWarning(
"22.1",
build_deprecation_warning_message(
deprecated_name="can_send_gift",
new_name="accepted_gift_types",
object_type="parameter",
bot_api_version="9.0",
),
),
stacklevel=2,
)

# Required and unique to this class-
with self._unfrozen():
self.max_reaction_count: int = max_reaction_count
Expand Down Expand Up @@ -575,28 +544,8 @@ def __init__(
self.business_location: Optional[BusinessLocation] = business_location
self.business_opening_hours: Optional[BusinessOpeningHours] = business_opening_hours
self.can_send_paid_media: Optional[bool] = can_send_paid_media
self._can_send_gift: Optional[bool] = can_send_gift
self.accepted_gift_types: AcceptedGiftTypes = accepted_gift_types

@property
def can_send_gift(self) -> Optional[bool]:
"""
:obj:`bool`: Optional. :obj:`True`, if gifts can be sent to the chat.

.. deprecated:: 22.1
As Bot API 9.0 replaces this attribute with :attr:`accepted_gift_types`, this attribute
will be removed in future versions.

"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="can_send_gift",
new_attr_name="accepted_gift_types",
bot_api_version="9.0",
ptb_version="22.1",
stacklevel=2,
)
return self._can_send_gift

@property
def slow_mode_delay(self) -> Optional[Union[int, dtm.timedelta]]:
return get_timedelta_value(self._slow_mode_delay, attribute="slow_mode_delay")
Expand Down
7 changes: 1 addition & 6 deletions src/telegram/_payment/stars/transactionpartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class TransactionPartnerUser(TransactionPartner):

def __init__(
self,
transaction_type: str,
user: "User",
invoice_payload: Optional[str] = None,
paid_media: Optional[Sequence[PaidMedia]] = None,
Expand All @@ -424,17 +425,11 @@ def __init__(
gift: Optional[Gift] = None,
affiliate: Optional[AffiliateInfo] = None,
premium_subscription_duration: Optional[int] = None,
# temporarily optional to account for changed signature
transaction_type: Optional[str] = None,
*,
api_kwargs: Optional[JSONDict] = None,
) -> None:
super().__init__(type=TransactionPartner.USER, api_kwargs=api_kwargs)

# tags: deprecated 22.1, bot api 9.0
if transaction_type is None:
raise TypeError("`transaction_type` is a required argument since Bot API 9.0")

with self._unfrozen():
self.user: User = user
self.affiliate: Optional[AffiliateInfo] = affiliate
Expand Down
57 changes: 10 additions & 47 deletions src/telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
.. versionchanged:: 20.0

* Most of the constants in this module are grouped into enums.

.. versionremoved:: NEXT.VERSION
Removed deprecated class ``StarTransactions``. Please instead use
:attr:`telegram.constants.Nanostar.VALUE`.
"""
# TODO: Remove this when https://github.com/PyCQA/pylint/issues/6887 is resolved.
# pylint: disable=invalid-enum-extension,invalid-slots
Expand Down Expand Up @@ -103,7 +107,6 @@
"ReactionType",
"ReplyLimit",
"RevenueWithdrawalStateType",
"StarTransactions",
"StarTransactionsLimit",
"StickerFormat",
"StickerLimit",
Expand Down Expand Up @@ -2737,36 +2740,18 @@ class RevenueWithdrawalStateType(StringEnum):
""":obj:`str`: A withdrawal failed and the transaction was refunded."""


# tags: deprecated 22.1, bot api 9.0
class StarTransactions(FloatEnum):
"""This enum contains constants for :class:`telegram.StarTransaction`.
The enum members of this enumeration are instances of :class:`float` and can be treated as
such.

.. versionadded:: 21.9

.. deprecated:: 22.1
This class will be removed as its only member :attr:`NANOSTAR_VALUE` will be replaced
by :attr:`telegram.constants.Nanostar.VALUE`.
"""

__slots__ = ()

NANOSTAR_VALUE = Nanostar.VALUE
""":obj:`float`: The value of one nanostar as used in
:attr:`telegram.StarTransaction.nanostar_amount`.

.. deprecated:: 22.1
This member will be replaced by :attr:`telegram.constants.Nanostar.VALUE`.
"""


class StarTransactionsLimit(IntEnum):
"""This enum contains limitations for :class:`telegram.Bot.get_star_transactions` and
:class:`telegram.StarTransaction`.
The enum members of this enumeration are instances of :class:`int` and can be treated as such.

.. versionadded:: 21.4

.. versionremoved:: NEXT.VERSION
Removed deprecated attributes ``StarTransactionsLimit.NANOSTAR_MIN_AMOUNT``
and ``StarTransactionsLimit.NANOSTAR_MAX_AMOUNT``. Please instead use
:attr:`telegram.constants.NanostarLimit.MIN_AMOUNT`
and :attr:`telegram.constants.NanostarLimit.MAX_AMOUNT`.
"""

__slots__ = ()
Expand All @@ -2779,28 +2764,6 @@ class StarTransactionsLimit(IntEnum):
""":obj:`int`: Maximum value allowed for the
:paramref:`~telegram.Bot.get_star_transactions.limit` parameter of
:meth:`telegram.Bot.get_star_transactions`."""
# tags: deprecated 22.1, bot api 9.0
NANOSTAR_MIN_AMOUNT = NanostarLimit.MIN_AMOUNT
""":obj:`int`: Minimum value allowed for :paramref:`~telegram.AffiliateInfo.nanostar_amount`
parameter of :class:`telegram.AffiliateInfo`.

.. versionadded:: 21.9

.. deprecated:: 22.1
This member will be replaced by :attr:`telegram.constants.NanostarLimit.MIN_AMOUNT`.
"""
# tags: deprecated 22.1, bot api 9.0
NANOSTAR_MAX_AMOUNT = NanostarLimit.MAX_AMOUNT
""":obj:`int`: Maximum value allowed for :paramref:`~telegram.StarTransaction.nanostar_amount`
parameter of :class:`telegram.StarTransaction` and
:paramref:`~telegram.AffiliateInfo.nanostar_amount` parameter of
:class:`telegram.AffiliateInfo`.

.. versionadded:: 21.9

.. deprecated:: 22.1
This member will be replaced by :attr:`telegram.constants.NanostarLimit.MAX_AMOUNT`.
"""


class StickerFormat(StringEnum):
Expand Down
8 changes: 2 additions & 6 deletions tests/_payment/stars/test_transactionpartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,15 @@ def test_to_dict(self, transaction_partner_user):
assert json_dict["subscription_period"] == self.subscription_period.total_seconds()
assert json_dict["premium_subscription_duration"] == self.premium_subscription_duration

def test_transaction_type_is_required_argument(self):
with pytest.raises(TypeError, match="`transaction_type` is a required argument"):
TransactionPartnerUser(user=self.user)

def test_equality(self, transaction_partner_user):
a = transaction_partner_user
b = TransactionPartnerUser(
user=self.user,
transaction_type=self.transaction_type,
user=self.user,
)
c = TransactionPartnerUser(
user=User(id=1, is_bot=False, first_name="user", last_name="user"),
transaction_type=self.transaction_type,
user=User(id=1, is_bot=False, first_name="user", last_name="user"),
)
d = User(id=1, is_bot=False, first_name="user", last_name="user")

Expand Down
3 changes: 2 additions & 1 deletion tests/auxil/dummy_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BotDescription,
BotName,
BotShortDescription,
BusinessBotRights,
BusinessConnection,
Chat,
ChatAdministratorRights,
Expand Down Expand Up @@ -69,8 +70,8 @@
id="123",
user_chat_id=123456,
date=_DUMMY_DATE,
can_reply=True,
is_enabled=True,
rights=BusinessBotRights(can_reply=True),
),
"Chat": Chat(id=123456, type="dummy_type"),
"ChatAdministratorRights": ChatAdministratorRights.all_rights(),
Expand Down
Loading
Loading