[Python-Dev] Allowing u.encode() to return non-strings
mike at skew.org
Wed Jun 16 17:15:27 EDT 2004
M.-A. Lemburg wrote:
> Now that more and more codecs become available and the scope
> of those codecs goes far beyond only encoding from Unicode to
> strings and back, I am tempted to open up that restriction,
> thereby opening up u.encode() for applications that wish to
> use other codecs that return e.g. Unicode objects as well.
> Note that codecs are not restricted in what they can return
> for their .encode() or .decode() method, so any object
> type is acceptable, including subclasses of str or
> unicode, buffers, mmapped files, etc.
+1. I find it surprising that the restriction exists. I would have thought
u.encode('foo') would pretty transparently wrap the foo codec's .encode().
This is also a good reminder that type checking of the result of codec or
unicode .encode() calls is prudent, anytime.
More information about the Python-Dev