-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-134759: UnboundLocalError
in email.message.Message.get_payload
#136071
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
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Misc/NEWS.d/next/Library/2025-06-28-11-32-57.gh-issue-134759.AjjKcG.rst
Outdated
Show resolved
Hide resolved
…jjKcG.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Lib/test/test_email/test_message.py
Outdated
def test_get_bytes_payload_with_quoted_printable_encoding(self): | ||
payload = b'Some payload' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_get_bytes_payload_with_quoted_printable_encoding(self): | |
payload = b'Some payload' | |
def test_get_bytes_payload_with_quoted_printable_encoding(self): | |
# See https://github.com/python/cpython/issues/134759. | |
payload = b'Some payload' |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the following for only using public methods:
payload = memoryview(b'Some payload')
m = self._make_message()
m.add_header('Content-Transfer-Encoding', 'quoted-printable')
m.set_payload(payload)
self.assertEqual(m.get_payload(decode=True), payload)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was trying to reproduce bug with "public" method .set_payload()
. I'm achieved that by passing BytesIO(b"Some payload")
buffer but was not sure about correct arg type of .set_payload()
(typeshed want object only with the .decode()
method), so came up to put bytes directly.
I'll change the way you suggest, no problem :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, decode()
is not present on memoryview but it's a buffer-like protocol so I think it should be fine. However, this may be a side-effect of the current implementation :) (also, the current implementation only does duck typing, not true isinstance() checks when setting the payload)
Hello!
I worked on #134759 and was able to reproduce the
UnboundLocalError
by passing bytes payload directly to_payload
. I'm not sure can we do it in a "public" way, like throw.set_payload()
but if payload some how become bytes (and content-transfer-encoding is equal quoted-printable) it is now not falling :)I'm also add myself to ACKS list, but not sure is my changes enough for it. If you say I'll remove myself with no questions.
UnboundLocalError
inemail.message.Message.get_payload
#134759