Ezio Melotti added the comment:

The attached proof of concept catches Type/ValueError in str.encode and raises 
another exception with a better message:
>>> 'example'.encode('hex_codec')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: invalid input type for hex_codec codec ('str' does not support the 
buffer interface)

(note: the patch doesn't handle the exception chaining yet and probably leaks.)

If Nick proposal in msg187704 is accepted, this should become a 
codecs.EncodeTypeError.  The same should then be done for bytes.decode and for 
codecs.encode/decode.

----------
Added file: http://bugs.python.org/file30190/issue17828-2.diff

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

Reply via email to