mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-27 08:50:38 +01:00
This commit is contained in:
parent
63977ea353
commit
61b70efb4c
2 changed files with 7 additions and 34 deletions
|
@ -29,8 +29,6 @@ from telegram._utils import enum
|
||||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||||
from telegram._utils.types import JSONDict
|
from telegram._utils.types import JSONDict
|
||||||
from telegram._utils.warnings import warn
|
|
||||||
from telegram.warnings import PTBDeprecationWarning
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from telegram import Bot
|
from telegram import Bot
|
||||||
|
@ -89,9 +87,11 @@ class PollAnswer(TelegramObject):
|
||||||
|
|
||||||
.. versionchanged:: 20.5
|
.. versionchanged:: 20.5
|
||||||
The order of :paramref:`option_ids` and :paramref:`user` is changed in
|
The order of :paramref:`option_ids` and :paramref:`user` is changed in
|
||||||
20.5 as the latter one became optional. We currently provide
|
20.5 as the latter one became optional.
|
||||||
backward compatibility for this but it will be removed in the future.
|
|
||||||
Please update your code to use the new order.
|
.. versionchanged:: NEXT.VERSION
|
||||||
|
Backward compatiblity for changed order of :paramref:`option_ids` and :paramref:`user`
|
||||||
|
was removed.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
poll_id (:obj:`str`): Unique poll identifier.
|
poll_id (:obj:`str`): Unique poll identifier.
|
||||||
|
@ -145,21 +145,8 @@ class PollAnswer(TelegramObject):
|
||||||
super().__init__(api_kwargs=api_kwargs)
|
super().__init__(api_kwargs=api_kwargs)
|
||||||
self.poll_id: str = poll_id
|
self.poll_id: str = poll_id
|
||||||
self.voter_chat: Optional[Chat] = voter_chat
|
self.voter_chat: Optional[Chat] = voter_chat
|
||||||
|
self.option_ids: Tuple[int, ...] = parse_sequence_arg(option_ids)
|
||||||
if isinstance(option_ids, User) or isinstance(user, tuple):
|
self.user: Optional[User] = user
|
||||||
warn(
|
|
||||||
"From v20.5 the order of `option_ids` and `user` is changed as the latter one"
|
|
||||||
" became optional. Please update your code to use the new order.",
|
|
||||||
category=PTBDeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
self.option_ids: Tuple[int, ...] = parse_sequence_arg(user)
|
|
||||||
self.user: Optional[User] = option_ids
|
|
||||||
else:
|
|
||||||
self.option_ids: Tuple[int, ...] = parse_sequence_arg( # type: ignore[no-redef]
|
|
||||||
option_ids
|
|
||||||
)
|
|
||||||
self.user: Optional[User] = user # type: ignore[no-redef]
|
|
||||||
|
|
||||||
self._id_attrs = (
|
self._id_attrs = (
|
||||||
self.poll_id,
|
self.poll_id,
|
||||||
|
|
|
@ -22,7 +22,6 @@ import pytest
|
||||||
from telegram import Chat, MessageEntity, Poll, PollAnswer, PollOption, User
|
from telegram import Chat, MessageEntity, Poll, PollAnswer, PollOption, User
|
||||||
from telegram._utils.datetime import UTC, to_timestamp
|
from telegram._utils.datetime import UTC, to_timestamp
|
||||||
from telegram.constants import PollType
|
from telegram.constants import PollType
|
||||||
from telegram.warnings import PTBDeprecationWarning
|
|
||||||
from tests.auxil.slots import mro_slots
|
from tests.auxil.slots import mro_slots
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,19 +143,6 @@ class TestPollAnswerWithoutRequest(TestPollAnswerBase):
|
||||||
assert a != f
|
assert a != f
|
||||||
assert hash(a) != hash(f)
|
assert hash(a) != hash(f)
|
||||||
|
|
||||||
def test_order_warning(self, recwarn):
|
|
||||||
expected_warning = (
|
|
||||||
"From v20.5 the order of `option_ids` and `user` is changed as the latter one"
|
|
||||||
" became optional. Please update your code to use the new order."
|
|
||||||
)
|
|
||||||
PollAnswer(123, [2], self.user, self.voter_chat)
|
|
||||||
assert len(recwarn) == 0
|
|
||||||
PollAnswer(123, self.user, [2], self.voter_chat)
|
|
||||||
assert len(recwarn) == 1
|
|
||||||
assert str(recwarn[0].message) == expected_warning
|
|
||||||
assert recwarn[0].category is PTBDeprecationWarning
|
|
||||||
assert recwarn[0].filename == __file__, "wrong stacklevel"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def poll():
|
def poll():
|
||||||
|
|
Loading…
Add table
Reference in a new issue