Remove Functionality Deprecated by Bot API 7.2 (#4245)

This commit is contained in:
Bibo-Joshi 2024-05-10 17:42:22 +02:00 committed by GitHub
parent c34f4811ea
commit ee6e82d7ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 165 deletions

View file

@ -6312,7 +6312,6 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
name: str,
title: str,
stickers: Sequence["InputSticker"],
sticker_format: Optional[str] = None,
sticker_type: Optional[str] = None,
needs_repainting: Optional[bool] = None,
*,
@ -6339,6 +6338,9 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
Removed the deprecated parameters mentioned above and adjusted the order of the
parameters.
.. versionremoved:: NEXT.VERSION
Removed the deprecated parameter ``sticker_format``.
Args:
user_id (:obj:`int`): User identifier of created sticker set owner.
name (:obj:`str`): Short name of sticker set, to be used in t.me/addstickers/ URLs
@ -6358,16 +6360,6 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
.. versionadded:: 20.2
sticker_format (:obj:`str`): Format of stickers in the set, must be one of
:attr:`~telegram.constants.StickerFormat.STATIC`,
:attr:`~telegram.constants.StickerFormat.ANIMATED` or
:attr:`~telegram.constants.StickerFormat.VIDEO`.
.. versionadded:: 20.2
.. deprecated:: 21.1
Use :paramref:`telegram.InputSticker.format` instead.
sticker_type (:obj:`str`, optional): Type of stickers in the set, pass
:attr:`telegram.Sticker.REGULAR` or :attr:`telegram.Sticker.MASK`, or
:attr:`telegram.Sticker.CUSTOM_EMOJI`. By default, a regular sticker set is created
@ -6387,20 +6379,11 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
Raises:
:class:`telegram.error.TelegramError`
"""
if sticker_format is not None:
warn(
"The parameter `sticker_format` is deprecated. Use the parameter"
" `InputSticker.format` in the parameter `stickers` instead.",
stacklevel=2,
category=PTBDeprecationWarning,
)
data: JSONDict = {
"user_id": user_id,
"name": name,
"title": title,
"stickers": stickers,
"sticker_format": sticker_format,
"sticker_type": sticker_type,
"needs_repainting": needs_repainting,
}

View file

@ -27,8 +27,6 @@ from telegram._telegramobject import TelegramObject
from telegram._utils import enum
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
from telegram._utils.warnings import warn
from telegram.warnings import PTBDeprecationWarning
if TYPE_CHECKING:
from telegram import Bot
@ -237,20 +235,12 @@ class StickerSet(TelegramObject):
.. versionchanged:: 20.5
|removed_thumb_note|
.. versionremoved:: NEXT.VERSION
Removed the deprecated arguments and attributes ``is_animated`` and ``is_video``.
Args:
name (:obj:`str`): Sticker set name.
title (:obj:`str`): Sticker set title.
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
.. deprecated:: 21.1
Bot API 7.2 deprecated this field. This parameter will be removed in a future
version of the library.
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
.. deprecated:: 21.1
Bot API 7.2 deprecated this field. This parameter will be removed in a future
version of the library.
stickers (Sequence[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
@ -269,17 +259,6 @@ class StickerSet(TelegramObject):
Attributes:
name (:obj:`str`): Sticker set name.
title (:obj:`str`): Sticker set title.
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
.. deprecated:: 21.1
Bot API 7.2 deprecated this field. This parameter will be removed in a future
version of the library.
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
.. deprecated:: 21.1
Bot API 7.2 deprecated this field. This parameter will be removed in a future
version of the library.
stickers (Tuple[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
@ -297,8 +276,6 @@ class StickerSet(TelegramObject):
"""
__slots__ = (
"is_animated",
"is_video",
"name",
"sticker_type",
"stickers",
@ -312,8 +289,6 @@ class StickerSet(TelegramObject):
title: str,
stickers: Sequence[Sticker],
sticker_type: str,
is_animated: Optional[bool] = None,
is_video: Optional[bool] = None,
thumbnail: Optional[PhotoSize] = None,
*,
api_kwargs: Optional[JSONDict] = None,
@ -325,15 +300,6 @@ class StickerSet(TelegramObject):
self.sticker_type: str = sticker_type
# Optional
self.thumbnail: Optional[PhotoSize] = thumbnail
if is_animated is not None or is_video is not None:
warn(
"The parameters `is_animated` and `is_video` are deprecated and will be removed "
"in a future version.",
PTBDeprecationWarning,
stacklevel=2,
)
self.is_animated: Optional[bool] = is_animated
self.is_video: Optional[bool] = is_video
self._id_attrs = (self.name,)
self._freeze()
@ -350,7 +316,7 @@ class StickerSet(TelegramObject):
api_kwargs = {}
# These are deprecated fields that TG still returns for backwards compatibility
# Let's filter them out to speed up the de-json process
for deprecated_field in ("contains_masks", "thumb"):
for deprecated_field in ("contains_masks", "thumb", "is_animated", "is_video"):
if deprecated_field in data:
api_kwargs[deprecated_field] = data.pop(deprecated_field)

View file

@ -23,12 +23,6 @@ from telegram._files.photosize import PhotoSize
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
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._bot import Bot
@ -44,11 +38,14 @@ class UsersShared(TelegramObject):
.. versionadded:: 20.8
Bot API 7.0 replaces ``UserShared`` with this class. The only difference is that now
the :attr:`user_ids` is a sequence instead of a single integer.
the ``user_ids`` is a sequence instead of a single integer.
.. versionchanged:: 21.1
The argument :attr:`users` is now considered for the equality comparison instead of
:attr:`user_ids`.
``user_ids``.
.. versionremoved:: NEXT.VERSION
Removed the deprecated argument and attribute ``user_ids``.
Args:
request_id (:obj:`int`): Identifier of the request.
@ -57,18 +54,8 @@ class UsersShared(TelegramObject):
.. versionadded:: 21.1
.. deprecated:: 21.1
In future versions, this argument will become keyword only.
user_ids (Sequence[:obj:`int`], optional): Identifiers of the shared users. These numbers
may have more than 32 significant bits and some programming languages may have
difficulty/silent defects in interpreting them. But they have at most 52 significant
bits, so 64-bit integers or double-precision float types are safe for storing these
identifiers. The bot may not have access to the users and could be unable to use
these identifiers, unless the users are already known to the bot by some other means.
.. deprecated:: 21.1
Bot API 7.2 introduced by :paramref:`users`, replacing this argument. Hence, this
argument is now optional and will be removed in future versions.
.. versionchanged:: NEXT.VERSION
This argument is now required.
Attributes:
request_id (:obj:`int`): Identifier of the request.
@ -83,31 +70,14 @@ class UsersShared(TelegramObject):
def __init__(
self,
request_id: int,
user_ids: Optional[Sequence[int]] = None,
users: Optional[Sequence["SharedUser"]] = None,
users: Sequence["SharedUser"],
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
self.request_id: int = request_id
if users is None:
raise TypeError("`users` is a required argument since Bot API 7.2")
self.users: Tuple[SharedUser, ...] = parse_sequence_arg(users)
if user_ids is not None:
warn(
build_deprecation_warning_message(
deprecated_name="user_ids",
new_name="users",
object_type="parameter",
bot_api_version="7.2",
),
PTBDeprecationWarning,
stacklevel=2,
)
self._id_attrs = (self.request_id, self.users)
self._freeze()
@ -130,28 +100,6 @@ class UsersShared(TelegramObject):
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
@property
def user_ids(self) -> Tuple[int, ...]:
"""
Tuple[:obj:`int`]: Identifiers of the shared users. These numbers may have
more than 32 significant bits and some programming languages may have difficulty/silent
defects in interpreting them. But they have at most 52 significant bits, so 64-bit
integers or double-precision float types are safe for storing these identifiers. The
bot may not have access to the users and could be unable to use these identifiers,
unless the users are already known to the bot by some other means.
.. deprecated:: 21.1
As Bot API 7.2 replaces this attribute with :attr:`users`, this attribute will be
removed in future versions.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="user_ids",
new_attr_name="users",
bot_api_version="7.2",
stacklevel=2,
)
return tuple(user.user_id for user in self.users)
class ChatShared(TelegramObject):
"""

View file

@ -1185,7 +1185,6 @@ class ExtBot(Bot, Generic[RLARGS]):
name: str,
title: str,
stickers: Sequence["InputSticker"],
sticker_format: Optional[str] = None,
sticker_type: Optional[str] = None,
needs_repainting: Optional[bool] = None,
*,
@ -1201,7 +1200,6 @@ class ExtBot(Bot, Generic[RLARGS]):
name=name,
title=title,
stickers=stickers,
sticker_format=sticker_format,
sticker_type=sticker_type,
needs_repainting=needs_repainting,
read_timeout=read_timeout,

View file

@ -39,7 +39,6 @@ from telegram import (
from telegram.constants import ParseMode, StickerFormat, StickerType
from telegram.error import BadRequest, TelegramError
from telegram.request import RequestData
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.bot_method_checks import (
check_defaults_handling,
check_shortcut_call,
@ -714,7 +713,6 @@ class TestStickerSetWithoutRequest(TestStickerSetBase):
assert data["name"] == "name"
assert data["title"] == "title"
assert data["stickers"] == ["wow.png", "wow.tgs", "wow.webp"]
assert data["sticker_format"] == "static"
assert data["needs_repainting"] is True
monkeypatch.setattr(bot, "_post", make_assertion)
@ -723,7 +721,6 @@ class TestStickerSetWithoutRequest(TestStickerSetBase):
"name",
"title",
stickers=["wow.png", "wow.tgs", "wow.webp"],
sticker_format=StickerFormat.STATIC,
needs_repainting=True,
)
@ -784,27 +781,6 @@ class TestStickerSetWithoutRequest(TestStickerSetBase):
monkeypatch.setattr(sticker.get_bot(), "get_file", make_assertion)
assert await sticker.get_file()
async def test_create_new_sticker_set_format_arg_depr(
self, bot, chat_id, sticker_file, monkeypatch
):
async def make_assertion(*_, **kwargs):
pass
monkeypatch.setattr(bot, "_post", make_assertion)
with pytest.warns(PTBDeprecationWarning, match="`sticker_format` is deprecated"):
await bot.create_new_sticker_set(
chat_id,
"name",
"title",
stickers=sticker_file,
sticker_format="static",
)
async def test_deprecation_creation_args(self, recwarn):
with pytest.warns(PTBDeprecationWarning, match="The parameters `is_animated` and ") as w:
StickerSet("name", "title", [], "static", is_animated=True)
assert w[0].filename == __file__, "wrong stacklevel!"
@pytest.mark.xdist_group("stickerset")
class TestStickerSetWithRequest:

View file

@ -166,11 +166,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]] = {
"create_new_sticker_set": {"sticker_format"}, # removed by bot api 7.2
"StickerSet": {"is_animated", "is_video"}, # removed by bot api 7.2
"UsersShared": {"user_ids", "users"}, # removed/added by bot api 7.2
}
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}
def backwards_compat_kwargs(object_name: str) -> set[str]:

View file

@ -20,7 +20,6 @@
import pytest
from telegram import ChatShared, PhotoSize, SharedUser, UsersShared
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.slots import mro_slots
@ -59,24 +58,9 @@ class TestUsersSharedWithoutRequest(TestUsersSharedBase):
assert users_shared.request_id == self.request_id
assert users_shared.users == self.users
assert users_shared.user_ids == tuple(self.user_ids)
assert UsersShared.de_json({}, bot) is None
def test_users_is_required_argument(self):
with pytest.raises(TypeError, match="`users` is a required argument"):
UsersShared(self.request_id, user_ids=self.user_ids)
def test_user_ids_deprecation_warning(self):
with pytest.warns(
PTBDeprecationWarning, match="'user_ids' was renamed to 'users' in Bot API 7.2"
):
users_shared = UsersShared(self.request_id, user_ids=self.user_ids, users=self.users)
with pytest.warns(
PTBDeprecationWarning, match="renamed the attribute 'user_ids' to 'users'"
):
users_shared.user_ids
def test_equality(self):
a = UsersShared(self.request_id, users=self.users)
b = UsersShared(self.request_id, users=self.users)