Ezio Melotti added the comment:

To summarize:
 * str.encode does only str->bytes;
 * bytes.decode does only bytes-> str;
 * codecs.encode/decode do obj->obj;

The things that could go wrong are:
 1) the input type is wrong (i.e. the codec doesn't accept the type of the 
input);
 2) the input value is invalid;
 3) for str.encode/bytes.decode only, the output type is wrong (i.e. the codec 
returned a non-bytes/non-str object);

My patch only covers 3.  The four new exceptions suggested by Nick in msg187704 
would cover the first 2 cases.
For str.encode/bytes.decode, if we knew the input type accepted by the codec we 
could also provide a better error message (e.g. "codecs accepts '...', not 
'...'; use ... instead"), but we don't.

----------

_______________________________________
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