[Python-Dev] transform() and untransform() methods, and the codec registry

Victor Stinner victor.stinner at haypocalc.com
Fri Dec 3 17:44:17 CET 2010


On Friday 03 December 2010 16:11:29 R. David Murray wrote:
> > >>> 'abc'.transform('hex')
> > TypeError: 'str' does not support the buffer interface
> > 
> > >>> b'abc'.transform('rot13')
> > TypeError: expected an object with the buffer interface
> 
> I find these 'buffer interface' error messages to be the most confusing
> error message I get out of Python3 no matter what context they show up
> in.  I have no idea what they are telling me.  That issue is more
> general than transform/untransform, but perhaps it could be fixed
> for transform/untransform in particular.

If it's more general, let's open an issue for that:
http://bugs.python.org/issue10616

> > >>> b'abcd'.decode('hex')
> > TypeError: decoder did not return a str object (type=bytes)
> > 
> > >>> 'abc'.encode('rot13')
> > TypeError: encoder did not return a bytes object (type=str)
> 
> These error messages make perfect sense to me.  I think it
> is called "duck typing" :)
>
> (...) 
>
> Please also recall that transform/untransform was discussed before
> the release of Python 3.0 and was approved at the time, but it just
> did not get implemented before the 3.0 release.

Ok.

Victor


More information about the Python-Dev mailing list