[Python-Dev] Wierd buffer "add" behaviour.
Mon, 16 Oct 2000 06:01:26 -0700
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.
Ideally, it might be nice to allow a string to append any object that
exports the buffer-interface. But when somebody goes and writes
"abc"+my_array ... hoo boy, will we hear complaints.
The alternative is to allow the buffer to resolve the type conflict and do
the appending within the buffer code.
Of course, the choice of returning a string (from buf+buf) rather than a
buffer was arguably the wrong choice.
Greg Stein, http://www.lyra.org/