Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feat: Deprecate payment attachment #4365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
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
16 changes: 14 additions & 2 deletions telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,8 @@ def effective_attachment(
Voice,
None,
]:
"""If this message is neither a plain text message nor a status update, this gives the
attachment that this message was sent with. This may be one of
"""If the message is a user generated content which is not a plain text message, this
property is set to this content. It may be one of

* :class:`telegram.Audio`
* :class:`telegram.Dice`
Expand Down Expand Up @@ -1419,13 +1419,25 @@ def effective_attachment(
.. versionchanged:: NEXT.VERSION
:attr:`paid_media` is now also considered to be an attachment.

.. deprecated:: NEXT.VERSION
:attr:`successful_payment` will be removed in future major versions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "major" is a bit confusing to me. Will it still be considered in minor version? same below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took that wording from https://github.com/python-telegram-bot/python-telegram-bot/blob/master/telegram%2F_passport%2Fpassportfile.py#L112

My understanding is that related to the stability policy the "next" major version removes it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, (git and) I will blame harshil, then :D I understand what it's supposed to mean, just stumbled on it on first read … If you like to keep it this way, I'll just merge :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rename both to mention the specific major version we drop the features?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I prefer not to mention specific versions beforehand - just gives use more freedom in case we need it …

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then Id stick with this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I put "major" versions cause of the stability policy


"""
if not isinstance(self._effective_attachment, DefaultValue):
return self._effective_attachment

for attachment_type in MessageAttachmentType:
if self[attachment_type]:
self._effective_attachment = self[attachment_type] # type: ignore[assignment]
if attachment_type == MessageAttachmentType.SUCCESSFUL_PAYMENT:
warn(
PTBDeprecationWarning(
"NEXT.VERSION",
"successful_payment will no longer be considered an attachment in"
" future major versions",
),
stacklevel=2,
)
break
else:
self._effective_attachment = None
Expand Down
12 changes: 12 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2774,3 +2774,15 @@ async def make_assertion(*_, **kwargs):

monkeypatch.setattr(message.get_bot(), "unpin_all_forum_topic_messages", make_assertion)
assert await message.unpin_all_forum_topic_messages()

def test_attachement_successful_payment_deprecated(self, message, recwarn):
message.successful_payment = "something"
# kinda unnecessary to assert but one needs to call the function ofc so. Here we are.
assert message.effective_attachment == "something"
assert len(recwarn) == 1
assert (
"successful_payment will no longer be considered an attachment in future major "
"versions" in str(recwarn[0].message)
)
assert recwarn[0].category is PTBDeprecationWarning
assert recwarn[0].filename == __file__
Loading