[Python-3000] Immutable bytes type and dbm modules
jimjjewett at gmail.com
Tue Aug 7 17:56:49 CEST 2007
On 8/7/07, Guido van Rossum <guido at python.org> wrote:
> On 8/7/07, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > This would mean that the Unicode type would acquire all of the ambiquity
> > currently associated with the 8-bit str type: does it contain actual
> > text, or does it contain arbitrary latin-1 decoded binary data?
> > 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.
I think that cost is already there, and we're making it even worse by
trying to use the same name for two distinct concepts.
(1) A mutable buffer
(2) A literal which isn't "characters"
Historically, most of the type(2) examples have just used ASCII (or at
least Latin-1) for convenience, so that they *look* like characters.
The actual requirements are on the bytes, though, so recoding them to
a different output format is not OK.
Also note that for type(2), immutability is important, not just for
efficiency, but conceptually. These are generally compile-time
constants, and letting them change *will* lead to confusion. (Even
letting them get replaced is confusing, but that sort of
monkey-patching is sufficiently rare and obvious that it seems to work
out OK today.)
More information about the Python-3000