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 <1368156157.04.0.266620918345.issue17828@psf.upfronthosting.co.za>
In-reply-to
Content
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')
'rknzcyr'
>>>
>>> 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')
b'\x00\x01\x02'

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/hex_codec.py", line 16, in hex_encode
    return (binascii.b2a_hex(input), len(input))
TypeError: 'str' does not support the buffer interface
History
Date User Action Args
2013-05-10 03:22:37ezio.melottisetrecipients: + ezio.melotti, barry, ncoghlan, flox
2013-05-10 03:22:37ezio.melottisetmessageid: <1368156157.04.0.266620918345.issue17828@psf.upfronthosting.co.za>
2013-05-10 03:22:37ezio.melottilinkissue17828 messages
2013-05-10 03:22:36ezio.melotticreate