-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-67022: Document bytes/str inconsistency in email.header.decode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative #92900
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
Conversation
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.
In general, I think this would help users of the legacy API, although I think we should also steer people to the new API. What does @bitdancer think?
Misc/NEWS.d/next/Library/2022-01-11-21-40-14.bpo-22833.WB-JWw.rst
Outdated
Show resolved
Hide resolved
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
I have made the requested changes; please review again, @warsaw.
😂 |
Thanks for making the requested changes! @warsaw: please review the changes made to this pull request. |
I have made the requested changes; please review again |
Thanks for making the requested changes! @warsaw: please review the changes made to this pull request. |
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
Per python#92900 (comment), not wanted for doc-only PRs.
…de_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior.
…email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
Per python#92900 (comment), not wanted for doc-only PRs.
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.
LGTM
Thanks @dlenski for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Thanks @dlenski for the PR, and @bitdancer for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…de_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (pythonGH-92900) * pythongh-67022: Document bytes/str inconsistency in email.header.decode_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior. Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment) (cherry picked from commit 60181f4) Co-authored-by: Dan Lenski <[email protected]>
GH-135548 is a backport of this pull request to the 3.14 branch. |
GH-135549 is a backport of this pull request to the 3.13 branch. |
…ode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (GH-92900) (#135548) gh-67022: Document bytes/str inconsistency in email.header.decode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (GH-92900) * gh-67022: Document bytes/str inconsistency in email.header.decode_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior. Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in #92900 (comment) (cherry picked from commit 60181f4) Co-authored-by: Dan Lenski <[email protected]>
…ode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (GH-92900) (#135549) gh-67022: Document bytes/str inconsistency in email.header.decode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (GH-92900) * gh-67022: Document bytes/str inconsistency in email.header.decode_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior. Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in #92900 (comment) (cherry picked from commit 60181f4) Co-authored-by: Dan Lenski <[email protected]>
…de_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (python#92900) * pythongh-67022: Document bytes/str inconsistency in email.header.decode_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior. Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
…de_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative (python#92900) * pythongh-67022: Document bytes/str inconsistency in email.header.decode_header() This function's possible return types have been surprising and error-prone for the entirety of its Python 3.x history. It can return either: 1. `typing.List[typing.Tuple[bytes, typing.Optional[str]]]` of length >1 2. or `typing.List[typing.Tuple[str, None]]`, of length exactly 1 This means that any user of this function must be prepared to accept either `bytes` or `str` for the first member of the 2-tuples it returns, which is a very surprising behavior in Python 3.x, particularly given that the second member of the tuple is supposed to represent the charset/encoding of the first member. This patch documents the behavior of this function, and adds test cases to demonstrate it. As discussed in bpo-22833, this cannot be changed in a backwards-compatible way, and some users of this function depend precisely on the existing behavior. Add warnings about obsolescence of 'email.header.decode_header' and 'email.header.make_header' functions. Recommend use of `email.headerregistry.HeaderRegistry` instead, as suggested in python#92900 (comment)
This function's possible return types have been surprising and error-prone
for the entirety of its Python 3.x history. It can return either:
This function can't be rewritten to be more consistent in a backwards-compatible way, because some users of this function depend on the existing return type(s).
This PR addresses the inconsistencies:
as suggested by @JelleZijlstra in The decode_header() function decodes raw part to bytes or str, depending on encoded part #67022 (comment):
by suggesting
email.headerregistry.HeaderRegistry
as a replacement, per gh-67022: Document bytes/str inconsistency in email.header.decode_header() and suggest email.headerregistry.HeaderRegistry as a sane alternative #92900Example of the old/inconsistent (
decode_header
) vs. modern/sane approaches:(Closes #30548 and replaces it.)