[Python-Dev] Fw: Behavior of buffer()

Guido van Rossum guido@python.org
Fri, 12 Jul 2002 13:24:31 -0400


> Guido van Rossum wrote:
> > I'm a little surprised.  Raymond Hettinger checked in a change that
> > makes all slices of buffer objects return strings.  His comments on SF
> > bug 546434 say that only one person replied and that they agreed
> > returning strings was the better solution.  But that's not how I read
> > the only response to his query that I see in python-dev, from Scott
> > Gilbert:
> 
> Interesting. I must have skipped that message.

You blink, and you find that the world has changed.

> IMHO, all slices of buffer object should return buffer objects,
> but since all Python releases return strings, I guess this is too
> late to change.

That was my preference too, but Raymond disagreed and somehow tried to
find support for his position :-).

Since buffer objects (of course :-) support the C-level buffer
protocol, they can still be used in most places where strings are
needed.  But it would be incompatible.  But so is Raymond's solution
(because it changes buffer()[:] to also return a string).

> Note that the only case where a buffer object
> is returned in Python 2.x (x < 3) is if you write
> buffer()[:], i.e. you want a copy of the buffer object.

What does a copy of a buffer object buy you?

It's not too late to revert Raymond's changes.

--Guido van Rossum (home page: http://www.python.org/~guido/)