This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JelleZijlstra
Recipients JelleZijlstra, barry, dlenski, iritkatriel, py.user, r.david.murray
Date 2022-01-21.01:48:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642729696.19.0.0234495672381.issue22833@roundup.psfhosted.org>
In-reply-to
Content
This behavior is definitely unfortunate, but by now it's also been baked into more than a decade of Python 3 releases, so backward compatibility constraints make it difficult to fix.

How can we be sure this change won't break users' code?

For reference, here are a few uses of the function I found in major open-source packages:
- https://github.com/httplib2/httplib2/blob/cde9e87d8b2c4c5fc966431965998ed5f45d19c7/python3/httplib2/__init__.py#L1608 - this assumes it only ever hits the (bytes, encoding) case.
- https://github.com/cherrypy/cherrypy/blob/98929b519fbca003cbf7b14a6b370a3cabc9c412/cherrypy/lib/httputil.py#L258 - this assumes it only gets (str, None) or (bytes, encoding) pairs, which seems unsafe. But if it currently sees (str, None) and would see (bytes, None) with this change, it would break.

An alternative solution could be a new function with a sane return type.

Even if we decide to not change anything, we should document the surprising return type at https://docs.python.org/3.10/library/email.header.html.
History
Date User Action Args
2022-01-21 01:48:16JelleZijlstrasetrecipients: + JelleZijlstra, barry, r.david.murray, py.user, dlenski, iritkatriel
2022-01-21 01:48:16JelleZijlstrasetmessageid: <1642729696.19.0.0234495672381.issue22833@roundup.psfhosted.org>
2022-01-21 01:48:16JelleZijlstralinkissue22833 messages
2022-01-21 01:48:16JelleZijlstracreate