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

Guido van Rossum guido@python.org
Tue, 28 Mar 2000 16:56:49 -0500


[Peter Funk]
> > > > Do we need a UserString class?
> > > 
> Andy Robinson:
> > > This will probably be useful on top of the i18n stuff in due course,
> > > so I'd like it.
> > > 
> > > Something Mike Da Silva and I have discussed a lot is implementing a
> > > higher-level 'typed string' library on top of the Unicode stuff.  
> > > A 'typed string' is like a string, but knows what encoding it is in -
> > > possibly Unicode, possibly a native encoding and embodies some basic
> > > type safety and convenience notions, like not being able to add a
> > > Shift-JIS and an EUC string together.  Iteration would always be per
> > > character, not per byte; and a certain amount of magic would say that
> > > if the string was (say) Japanese, it would acquire a few extra methods
> > > for doing some Japan-specific things like expanding half-width
> > > katakana.
> > > 
> > > Of course, we can do this anyway, but I think defining the API clearly
> > > in UserString is a great idea.
> > 
> Guido van Rossum:
> > Agreed.  Please somebody send a patch!

[PF]
> I feel unable to do, what Andy proposed.  What I had in mind was a
> simple wrapper class around the builtin string type similar to 
> UserDict and UserList which can be used to derive other classes from.

Yes.  I think Andy wanted his class to be a subclass of UserString.

> I use UserList and UserDict quite often and find them very useful.
> They are simple and powerful and easy to extend.

Agreed.

> May be the things Andy Robinson proposed above belong into a sub class
> which inherits from a simple UserString class?  Do we need
> an additional UserUnicode class for unicode string objects?

It would be great if there was a single UserString class which would
work with either Unicode or 8-bit strings.  I think that shouldn't be
too hard, since it's just a wrapper.

So why don't you give the UserString.py a try and leave Andy's wish alone?

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