[Python-3000] Immutable bytes type and dbm modules

Guido van Rossum guido at python.org
Tue Aug 7 18:39:26 CEST 2007


On 8/7/07, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Guido van Rossum wrote:
> > On 8/7/07, Nick Coghlan <ncoghlan at gmail.com> wrote:
> >> A separate frozenbytes type (with the bytes API instead of the
> >> string API) would solve the problem far more cleanly.
> >
> > But at a cost: an extra data type, more code to maintain, more docs
> > to write, thicker books, etc.
> >
> > To me, the most important cost is that every time you need to use
> > bytes you would have to think about whether to use frozen or mutable
> > bytes.
>
> I agree this cost exists, but I don't think it is very high. I would
> expect the situation to be the same as with sets - you'd use the mutable
> version by default, unless there was some specific reason to want the
> frozen version (usually because you want something that is hashable, or
> easy to share safely amongst multiple clients).

That would imply that b"..." should return a mutable bytes object,
which many people have objected to. If b"..." is immutable, the
immutable bytes type is in your face all the time and you'll have to
deal with the difference all the time. E.g. is the result of
concatenating a mutable and an immutable bytes object mutable? Does it
matter whether the mutable operand is first or second? Is a slice of
an immutable bytes array immutable itself?

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


More information about the Python-3000 mailing list