Where's UserList.ListMixin?

Discussion in 'Python' started by Matthew Barnes, Sep 18, 2003.

  1. 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
     
    Matthew Barnes, Sep 18, 2003
    #1
    1. Advertising

  2. [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
     
    Raymond Hettinger, Sep 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Replies:
    2
    Views:
    281
    Raymond Hettinger
    Mar 2, 2005
Loading...

Share This Page