[Python-Dev] Wierd buffer "add" behaviour.

M.-A. Lemburg mal@lemburg.com
Mon, 16 Oct 2000 19:42:15 +0200


Greg Stein wrote:
> 
> On Mon, Oct 16, 2000 at 09:50:22AM +0200, M.-A. Lemburg wrote:
> > Mark Hammond wrote:
> >...
> > > This yields the following strange behaviour:
> > >
> > > >>> a=buffer('a')
> > > >>> a+a
> > > 'aa'
> > > >>> a+a+a
> > > Traceback (innermost last):
> > >   File "<interactive input>", line 1, in ?
> > > TypeError: cannot add type "buffer" to string
> > > >>>
> > >
> > > That doesnt seem correct to me?
> >
> > Neither to me.
> 
> It is caused by the non-commutative aspect of Python types. You end up with
> a string, and that type doesn't know how to add a buffer to itself.

The problem is that buffer() objects coerce to strings in the
first place... they should return new buffer objects instead
of strings -- then we wouldn't have the above problems.
 
> ... 
> Of course, the choice of returning a string (from buf+buf) rather than a
> buffer was arguably the wrong choice.

Right :-/

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/