[issue17828] More informative error handling when encoding and decoding
Ezio Melotti
report at bugs.python.org
Fri May 10 05:52:40 CEST 2013
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 <report at bugs.python.org>
<http://bugs.python.org/issue17828>
_______________________________________
More information about the Python-bugs-list
mailing list