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, ezio.melotti, flox, ncoghlan
Date 2013-05-10.03:22:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The attached patch changes the error message of str.encode/bytes.decode when the codec returns the wrong type:

>>> import codecs
>>> 'example'.encode('rot_13')
TypeError: encoder returned 'str' instead of 'bytes', use codecs.decode for str->str conversions
>>> codecs.encode('example', 'rot_13')
>>> b'000102'.decode('hex_codec')
TypeError: decoder returned 'bytes' instead of 'str', use codecs.encode for bytes->bytes conversions
>>> codecs.decode(b'000102', 'hex_codec')

This only solves part of the problem though, because individual codecs might raise other errors if the input type is wrong:
>>> 'example'.encode('hex_codec')
Traceback (most recent call last):
  File "/home/wolf/dev/py/py3k/Lib/encodings/", line 16, in hex_encode
    return (binascii.b2a_hex(input), len(input))
TypeError: 'str' does not support the buffer interface
Date User Action Args
2013-05-10 03:22:37ezio.melottisetrecipients: + ezio.melotti, barry, ncoghlan, flox
2013-05-10 03:22:37ezio.melottisetmessageid: <>
2013-05-10 03:22:37ezio.melottilinkissue17828 messages
2013-05-10 03:22:36ezio.melotticreate