[Python-3000] PEP 3137 plan of attack

Guido van Rossum guido at python.org
Mon Oct 15 16:49:31 CEST 2007


On 10/15/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 10/12/07, Guido van Rossum <guido at python.org> wrote:
> > On 10/12/07, Gregory P. Smith <greg at krypto.org> wrote:
> > > > > - add missing methods to PyBytes (for list, see the PEP and compare to
> > > > > what's already there)
>
> > > As I work on these..  Should the mutable PyBytes_ (buffer) objects implement
> > > the following methods inplace and return an additional reference to self?
>
> > > .capitalize(), .center(), .expandtabs(), .rjust(), .swapcase(), .title(),
> > > .upper(), .zfill()
>
> > No... That would be a huge trap to fall in at all sorts of occasions.
>
> So would returning a different object.  I expect a mutation operation
> on an explicitly mutable object to mutate the object, instead of
> creating something new.
>
> If it returns a new one, I can imagine doing something like:
>
>     obj.inqueue=bytesbuffer(100)
>     obj.inqueue.lower()   # oh, wait, that didn't really do anything
> after all...
>     if obj.inqueue[:4] == b"http":   # works on my *regular* input...
>
> Maybe the answer is "don't do that", and to only do this sort of
> processing before it goes in the buffer or after it comes out, but ...
> it still looks like a major gotcha.

Since these methods with these very names already exist for strings
and return new values there, I don't see the gotcha unless you never
use strings.

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


More information about the Python-3000 mailing list