[Python-Dev] [1.6]: UserList, Dict: Do we need a UserString class?

Peter Funk pf@artcom-gmbh.de
Wed, 29 Mar 2000 12:35:32 +0200 (MEST)


> > Moshe Zadka:
> > > eagerly-waiting-for-UserString.py-ly y'rs, Z.
> > 
> On Wed, 29 Mar 2000, Peter Funk wrote:
> > Well, I've added the missing methods.  Unfortunately I ran out of time now and
> > a 'test_userstring.py' derived from 'src/Lib/test/test_string.py' is still 
> > missing.  
Moshe Zadka schrieb:
> Great work, Peter! I really like UserString. However, I have two issues
> with MutableString:
> 1. I tshouldn't share implementation with UserString, otherwise your
> algorithm are not behaving with correct big-O properties. It should
> probably use a char-array (from the array module) as the internal
> representation.

Hmm.... I don't understand what you mean with 'big-O properties'.  
The internal representation of any object should be considered ...
umm ... internal.

> 2. It shouldn't share interface iwth UserString, since it doesn't have a
> proper implementation with __hash__.

What's wrong with my implementation of __hash__ raising a TypeError with
the attribution 'unhashable object'.  This is the same behaviour, if 
you try to add some other mutable object as key to dictionary:

>>> l = []
>>> d = { l : 'foo' }
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: unhashable type

> All in all, I probably disagree with making MutableString a subclass of
> UserString. If I have time later today, I'm hoping to be able to make my
> own MutableString

As I tried to point out in the docstring of 'MutableString', I don't want 
people actually start using the 'MutableString' class.  My Intentation 
was to prevent people from trying to invent their own and than probably 
wrong MutableString class derived from UserString.  Only Newbies will really
ever need mutable strings in Python (see FAQ).

May be my 'MutableString' idea belongs somewhere into 
the to be written src/Doc/libuserstring.tex.  But since Newbies tend
to ignore docs ... Sigh.

Regards, Peter
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)