➜

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 ezio.melotti
Recipients barry, berker.peksag, docs@python, ezio.melotti, jim_minter, [email protected], r.david.murray
Date 2019-06-04.04:20:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
If we can't fix the behavior, it should at least be documented.

Currently the docs says "This function returns a list of (decoded_string, charset) pairs containing each of the decoded parts of the header.".  One could assume that this means that a Unicode string is returned, but and as far as I can tell, "decoded_string" means decoded from the format used by the header, not from bytes -- in fact the example below shows a byte string.
#24797 suggest an alternative solution, but there is no indications about it in the docs except an easy-to-miss note about the new API at the top.

Coincidentally as I was reporting this issue I also found the recently opened #37139.  There are also a few other reports: #24797, #37139, #32975, #6302, #4661.

If this method is not actually deprecated, I would document the current behavior (i.e. sometimes it returns bytes, sometimes unicode -- bonus points if there's a simple rule to predict which one), explain that it exists for legacy/backward-compatibility reasons, and point to the alternatives.


FWIW here are 3 more samples that show the inconsistency.

>>> from email.header import decode_header
>>> # str + None
>>> h = '\x80SOKCrGxsbw===== <[email protected]>'; decode_header(h)
[('\x80SOKCrGxsbw===== <[email protected]>', None)]
>>> # bytes + '', bytes + None
>>> h = '=??b?SOKCrGxsbw=====?= <[email protected]>'; decode_header(h)
[(b'H\xe2\x82\xacllo', ''), (b' <[email protected]>', None)]
>>> # bytes + 'utf8', bytes + None
>>> h = '=?utf8?b?SOKCrGxsbw==?= <[email protected]>'; decode_header(h)
[(b'H\xe2\x82\xacllo', 'utf8'), (b' <[email protected]>', None)]
History
Date User Action Args
2019-06-04 04:20:03ezio.melottisetrecipients: + ezio.melotti, barry, r.david.murray, docs@python, berker.peksag, jim_minter, [email protected]
2019-06-04 04:20:03ezio.melottisetmessageid: <[email protected]>
2019-06-04 04:20:03ezio.melottilinkissue21492 messages
2019-06-04 04:20:03ezio.melotticreate