Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Where's UserList.ListMixin?

Reply
Thread Tools

Where's UserList.ListMixin?

 
 
Matthew Barnes
Guest
Posts: n/a
 
      09-18-2003
This may be a naive question, but since Python 2.3 added a handy
little DictMixin class to its UserDict module it seems to me like
UserList.ListMixin and maybe even UserString.StringMixin should have
followed (although I'm not sure how useful a StringMixin class would
really be).

I'm just curious. Is there a reason these classes weren't included?
Is anybody looking into this for Python 2.4? Should I submit a patch?

Matthew Barnes
 
Reply With Quote
 
 
 
 
Raymond Hettinger
Guest
Posts: n/a
 
      09-18-2003
[Matthew Barnes]
> This may be a naive question, but since Python 2.3 added a handy
> little DictMixin class to its UserDict module it seems to me like
> UserList.ListMixin and maybe even UserString.StringMixin should have
> followed (although I'm not sure how useful a StringMixin class would
> really be).


Use cases have to come first. Do you see modules in the library
or in common applications where this has immediate use?
When I developed DickNixon, er, DictMixin (not the former President),
there were immediate applications in shelve, dumbdbm, and some of
my own apps.

As a starting point, look in calendar.py to see whether your idea
would have helped implement _localized_day and _localized_month.
I think these classes are typical of objects that try to dynamically
simulate list behavior.


> Should I submit a patch?


It is best to start by submitting a recipe to the ASPN Cookbook.
There, the idea can be refined, use cases established, and a fan
club formed. At that point, it could be a candidate for inclusion
in Py2.4.

It may be best to start which an easier challenge like TupleMixin
and then add mutuable behaviors to a ListMixin subclass. An
even easier start is to build a RichComparisonMixin that
transforms == and < into <=, >, >=, and !=.

If you want to show-off your agile programming skills, develop
the unittest cases before you write your code.

The most important part of the design is thinking out which methods
should be the primitives and whether there should be multiple
levels so that the most natural overrides get used by higher levels
(see the DictMixin code if you don't know what I'm talking about
here). Try to keep your thinking grounded in reality by examining
real modules which would benefit from subclassing the mixins.

Also, I'm curious as to how you would implement the sort()
method without actually manifesting the whole virtual list;
otherwise, you might as well use list(iterable) and get a real list
(which, BTW, is what _localized_day does using a list
comprehension).

Good luck with your project,


Raymond Hettinger


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments