Jelle Zijlstra <jelle.zijls...@gmail.com> added the comment:

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.

----------
nosy: +Jelle Zijlstra

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue22833>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to