8000 Remove Functionality Deprecated by Bot API 7.2 (#4245) · gtkacz/python-telegram-bot@ee6e82d · GitHub
[go: up one dir, main page]

Skip to content

Commit ee6e82d

Browse files
authored
Remove Functionality Deprecated by Bot API 7.2 (python-telegram-bot#4245)
1 parent c34f481 commit ee6e82d

File tree

7 files changed

+16
-165
lines changed

7 files changed

+16
-165
lines changed

telegram/_bot.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6312,7 +6312,6 @@ async def create_new_sticker_set(
63126312
name: str,
63136313
title: str,
63146314
stickers: Sequence["InputSticker"],
6315-
sticker_format: Optional[str] = None,
63166315
sticker_type: Optional[str] = None,
63176316
needs_repainting: Optional[bool] = None,
63186317
*,
@@ -6339,6 +6338,9 @@ async def create_new_sticker_set(
63396338
Removed the deprecated parameters mentioned above and adjusted the order of the
63406339
parameters.
63416340
6341+
.. versionremoved:: NEXT.VERSION
6342+
Removed the deprecated parameter ``sticker_format``.
6343+
63426344
Args:
63436345
user_id (:obj:`int`): User identifier of created sticker set owner.
63446346
name (:obj:`str`): Short name of sticker set, to be used in t.me/addstickers/ URLs
@@ -6358,16 +6360,6 @@ async def create_new_sticker_set(
63586360
63596361
.. versionadded:: 20.2
63606362
6361-
sticker_format (:obj:`str`): Format of stickers in the set, must be one of
6362-
:attr:`~telegram.constants.StickerFormat.STATIC`,
6363-
:attr:`~telegram.constants.StickerFormat.ANIMATED` or
6364-
:attr:`~telegram.constants.StickerFormat.VIDEO`.
6365-
6366-
.. versionadded:: 20.2
6367-
6368-
.. deprecated:: 21.1
6369-
Use :paramref:`telegram.InputSticker.format` instead.
6370-
63716363
sticker_type (:obj:`str`, optional): Type of stickers in the set, pass
63726364
:attr:`telegram.Sticker.REGULAR` or :attr:`telegram.Sticker.MASK`, or
63736365
:attr:`telegram.Sticker.CUSTOM_EMOJI`. By default, a regular sticker set is created
@@ -6387,20 +6379,11 @@ async def create_new_sticker_set(
63876379
Raises:
63886380
:class:`telegram.error.TelegramError`
63896381
"""
6390-
if sticker_format is not None:
6391-
warn(
6392-
"The parameter `sticker_format` is deprecated. Use the parameter"
6393-
" `InputSticker.format` in the parameter `stickers` instead.",
6394-
stacklevel=2,
6395-
category=PTBDeprecationWarning,
6396-
)
6397-
63986382
data: JSONDict = {
63996383
"user_id": user_id,
64006384
"name": name,
64016385
"title": title,
64026386
"stickers": stickers,
6403-
"sticker_format": sticker_format,
64046387
"sticker_type": sticker_type,
64056388
"needs_repainting": needs_repainting,
64066389
}

telegram/_files/sticker.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
from telegram._utils import enum
2828
from telegram._utils.argumentparsing import parse_sequence_arg
2929
from telegram._utils.types import JSONDict
30-
from telegram._utils.warnings import warn
31-
from telegram.warnings import PTBDeprecationWarning
3230

3331
if TYPE_CHECKING:
3432
from telegram import Bot
@@ -237,20 +235,12 @@ class StickerSet(TelegramObject):
237235
.. versionchanged:: 20.5
238236
|removed_thumb_note|
239237
238+
.. versionremoved:: NEXT.VERSION
239+
Removed the deprecated arguments and attributes ``is_animated`` and ``is_video``.
240+
240241
Args:
241242
name (:obj:`str`): Sticker set name.
242243
title (:obj:`str`): Sticker set title.
243-
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
244-
245-
.. deprecated:: 21.1
246-
Bot API 7.2 deprecated this field. This parameter will be removed in a future
247-
version of the library.
248-
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
249-
.. versionadded:: 13.11
250-
251-
.. deprecated:: 21.1
252-
Bot API 7.2 deprecated this field. This parameter will be removed in a future
253-
version of the library.
254244
stickers (Sequence[:class:`telegram.Sticker`]): List of all set stickers.
255245
256246
.. versionchanged:: 20.0
@@ -269,17 +259,6 @@ class StickerSet(TelegramObject):
269259
Attributes:
270260
name (:obj:`str`): Sticker set name.
271261
title (:obj:`str`): Sticker set title.
272-
is_animated (:obj:`bool`): :obj:`True`, if the sticker set contains animated stickers.
273-
274-
.. deprecated:: 21.1
275-
Bot API 7.2 deprecated this field. This parameter will be removed in a future
276-
version of the library.
277-
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
278-
.. versionadded:: 13.11
279-
280-
.. deprecated:: 21.1
281-
Bot API 7.2 deprecated this field. This parameter will be removed in a future
282-
version of the library.
283262
stickers (Tuple[:class:`telegram.Sticker`]): List of all set stickers.
284263
285264
.. versionchanged:: 20.0
@@ -297,8 +276,6 @@ class StickerSet(TelegramObject):
297276
"""
298277

299278
__slots__ = (
300-
"is_animated",
301-
"is_video",
302279
"name",
303280
"sticker_type",
304281
"stickers",
@@ -312,8 +289,6 @@ def __init__(
312289
title: str,
313290
stickers: Sequence[Sticker],
314291
sticker_type: str,
315-
is_animated: Optional[bool] = None,
316-
is_video: Optional[bool] = None,
317292
thumbnail: Optional[PhotoSize] = None,
318293
*,
319294
api_kwargs: Optional[JSONDict] = None,
@@ -325,15 +300,6 @@ def __init__(
325300
self.sticker_type: str = sticker_type
326301
# Optional
327302
self.thumbnail: Optional[PhotoSize] = thumbnail
328-
if is_animated is not None or is_video is not None:
329-
warn(
330-
"The parameters `is_animated` and `is_video` are deprecated and will be removed "
331-
"in a future version.",
332-
PTBDeprecationWarning,
333-
stacklevel=2,
334-
)
335-
self.is_animated: Optional[bool] = is_animated
336-
self.is_video: Optional[bool] = is_video
337303
self._id_attrs = (self.name,)
338304

339305
self._freeze()
@@ -350,7 +316,7 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["StickerSet"]
350316
api_kwargs = {}
351317
# These are deprecated fields that TG still returns for backwards compatibility
352318
# Let's filter them out to speed up the de-json process
353-
for deprecated_field in ("contains_masks", " 10000 thumb"):
319+
for deprecated_field in ("contains_masks", "thumb", "is_animated", "is_video"):
354320
if deprecated_field in data:
355321
api_kwargs[deprecated_field] = data.pop(deprecated_field)
356322

telegram/_shared.py

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
from telegram._telegramobject import TelegramObject
2424
from telegram._utils.argumentparsing import parse_sequence_arg
2525
from telegram._utils.types import JSONDict
26-
from telegram._utils.warnings import warn
27-
from telegram._utils.warnings_transition import (
28-
build_deprecation_warning_message,
29-
warn_about_deprecated_attr_in_property,
30-
)
31-
from telegram.warnings import PTBDeprecationWarning
3226

3327
if TYPE_CHECKING:
3428
from telegram._bot import Bot
@@ -44,11 +38,14 @@ class UsersShared(TelegramObject):
4438
4539
.. versionadded:: 20.8
4640
Bot API 7.0 replaces ``UserShared`` with this class. The only difference is that now
47-
the :attr:`user_ids` is a sequence instead of a single integer.
41+
the ``user_ids`` is a sequence instead of a single integer.
4842
4943
.. versionchanged:: 21.1
5044
The argument :attr:`users` is now considered for the equality comparison instead of
51-
:attr:`user_ids`.
45+
``user_ids``.
46+
47+
.. versionremoved:: NEXT.VERSION
48+
Removed the deprecated argument and attribute ``user_ids``.
5249
5350
Args:
5451
request_id (:obj:`int`): Identifier of the request.
@@ -57,18 +54,8 @@ class UsersShared(TelegramObject):
5754
5855
.. versionadded:: 21.1
5956
60-
.. deprecated:: 21.1
61-
In future versions, this argument will become keyword only.
62-
user_ids (Sequence[:obj:`int`], optional): Identifiers of the shared users. These numbers
63-
may have more than 32 significant bits and some programming languages may have
64-
difficulty/silent defects in interpreting them. But they have at most 52 significant
65-
bits, so 64-bit integers or double-precision float types are safe for storing these
66-
identifiers. The bot may not have access to the users and could be unable to use
67-
these identifiers, unless the users are already known to the bot by some other means.
68-
69-
.. deprecated:: 21.1
70-
Bot API 7.2 introduced by :paramref:`users`, replacing this argument. Hence, this
71-
argument is now optional and will be removed in future versions.
57+
.. versionchanged:: NEXT.VERSION
58+
This argument is now required.
7259
7360
Attributes:
7461
request_id (:obj:`int`): Identifier of the request.
@@ -83,31 +70,14 @@ class UsersShared(TelegramObject):
8370
def __init__(
8471
self,
8572
request_id: int,
86-
user_ids: Optional[Sequence[int]] = None,
87-
users: Optional[Sequence["SharedUser"]] = None,
73+
users: Sequence["SharedUser"],
8874
*,
8975
api_kwargs: Optional[JSONDict] = None,
9076
):
9177
super().__init__(api_kwargs=api_kwargs)
9278
self.request_id: int = request_id
93-
94-
if users is None:
95-
raise TypeError("`users` is a required argument since Bot API 7.2")
96-
9779
self.users: Tuple[SharedUser, ...] = parse_sequence_arg(users)
9880

99-
if user_ids is not None:
100-
warn(
101-
build_deprecation_warning_message(
102-
deprecated_name="user_ids",
103-
new_name="users",
104-
object_type="parameter",
105-
bot_api_version="7.2",
106-
),
107-
PTBDeprecationWarning,
108-
stacklevel=2,
109-
)
110-
11181
self._id_attrs = (self.request_id, self.users)
11282

11383
self._freeze()
@@ -130,28 +100,6 @@ def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["UsersShared"
130100

131101
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
132102

133-
@property
134-
def user_ids(self) -> Tuple[int, ...]:
135-
"""
136-
Tuple[:obj:`int`]: Identifiers of the shared users. These numbers may have
137-
more than 32 significant bits and some programming languages may have difficulty/silent
138-
defects in interpreting them. But they have at most 52 significant bits, so 64-bit
139-
integers or double-precision float types are safe for storing these identifiers. The
140-
bot may not have access to the users and could be unable to use these identifiers,
141-
unless the users are already known to the bot by some other means.
142-
143-
.. deprecated:: 21.1
144-
As Bot API 7.2 replaces this attribute with :attr:`users`, this attribute will be
145-
removed in future versions.
146-
"""
147-
warn_about_deprecated_attr_in_property(
148-
deprecated_attr_name="user_ids",
149-
new_attr_name="users",
150-
bot_api_version="7.2",
151-
stacklevel=2,
152-
)
153-
return tuple(user.user_id for user in self.users)
154-
155103

156104
class ChatShared(TelegramObject):
157105
"""

telegram/ext/_extbot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,6 @@ async def create_new_sticker_set(
11851185
name: str,
11861186
title: str,
11871187
stickers: Sequence["InputSticker"],
1188-
sticker_format: Optional[str] = None,
11891188
sticker_type: Optional[str] = None,
11901189
needs_repainting: Optional[bool] = None,
11911190
*,
@@ -1201,7 +1200,6 @@ async def create_new_sticker_set(
12011200
name=name,
12021201
title=title,
12031202
stickers=stickers,
1204-
sticker_format=sticker_format,
12051203
sticker_type=sticker_type,
12061204
needs_repainting=needs_repainting,
12071205
read_timeout=read_timeout,

tests/_files/test_sticker.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from telegram.constants import ParseMode, StickerFormat, StickerType
4040
from telegram.error import BadRequest, TelegramError
4141
from telegram.request import RequestData
42-
from telegram.warnings import PTBDeprecationWarning
4342
from tests.auxil.bot_method_checks import (
4443
check_defaults_handling,
4544
check_shortcut_call,
@@ -714,7 +713,6 @@ async def make_assertion(_, data, *args, **kwargs):
714713
assert data["name"] == "name"
715714
assert data["title"] == "title"
716715
assert data["stickers"] == ["wow.png", "wow.tgs", "wow.webp"]
717-
assert data["sticker_format"] == "static"
718716
assert data["needs_repainting"] is True
719717

720718
monkeypatch.setattr(bot, "_post", make_assertion)
@@ -723,7 +721,6 @@ async def make_assertion(_, data, *args, **kwargs):
723721
"name",
724722
"title",
725723
stickers=["wow.png", "wow.tgs", "wow.webp"],
726-
sticker_format=StickerFormat.STATIC,
727724
needs_repainting=True,
728725
)
729726

@@ -784,27 +781,6 @@ async def make_assertion(*_, **kwargs):
784781
monkeypatch.setattr(sticker.get_bot(), "get_file", make_assertion)
785782
assert await sticker.get_file()
786783

787-
async def test_create_new_sticker_set_format_arg_depr(
788-
self, bot, chat_id, sticker_file, monkeypatch
789-
):
790-
async def make_assertion(*_, **kwargs):
791-
pass
792-
793-
monkeypatch.setattr(bot, "_post", make_assertion)
794-
with pytest.warns(PTBDeprecationWarning, match="`sticker_format` is deprecated"):
795-
await bot.create_new_sticker_set(
796-
chat_id,
797-
"name",
798-
"title",
799-
stickers=sticker_file,
800-
sticker_format="static",
801-
)
802-
803-
async def test_deprecation_creation_args(self, recwarn):
804-
with pytest.warns(PTBDeprecationWarning, match="The parameters `is_animated` and ") as w:
805-
StickerSet("name", "title", [], "static", is_animated=True)
806-
assert w[0].filename == __file__, "wrong stacklevel!"
807-
808784

809785
@pytest.mark.xdist_group("stickerset")
810786
class TestStickerSetWithRequest:

tests/test_official/exceptions.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ def ignored_param_requirements(object_name: str) -> set[str]:
166166

167167

168168
# Arguments that are optional arguments for now for backwards compatibility
169-
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {
170-
"create_new_sticker_set": {"sticker_format"}, # removed by bot api 7.2
171-
"StickerSet": {"is_animated", "is_video"}, # removed by bot api 7.2
172-
"UsersShared": {"user_ids", "users"}, # removed/added by bot api 7.2
173-
}
169+
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}
174170

175171

176172
def backwards_compat_kwargs(object_name: str) -> set[str]:

tests/test_shared.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import pytest
2121

2222
from telegram import ChatShared, PhotoSize, SharedUser, UsersShared
23-
from telegram.warnings import PTBDeprecationWarning
2423
from tests.auxil.slots import mro_slots
2524

2625

@@ -59,24 +58,9 @@ def test_de_json(self, bot):
5958

6059
assert users_shared.request_id == self.request_id
6160
assert users_shared.users == self.users
62-
assert users_shared.user_ids == tuple(self.user_ids)
6361

6462
assert UsersShared.de_json({}, bot) is None
6563

66-
def test_users_is_required_argument(self):
67-
with pytest.raises(TypeError, match="`users` is a required argument"):
68-
UsersShared(self.request_id, user_ids=self.user_ids)
69-
70-
def test_user_ids_deprecation_warning(self):
71-
with pytest.warns(
72-
PTBDeprecationWarning, match="'user_ids' was renamed to 'users' in Bot API 7.2"
73-
):
74-
users_shared = UsersShared(self.request_id, user_ids=self.user_ids, users=self.users)
75-
with pytest.warns(
76-
PTBDeprecationWarning, match="renamed the attribute 'user_ids' to 'users'"
77-
):
78-
users_shared.user_ids
79-
8064
def test_equality(self):
8165
a = UsersShared(self.request_id, users=self.users)
8266
b = UsersShared(self.request_id, users=self.users)

0 commit comments

Comments
 (0)
0