Where's UserList.ListMixin?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Barnes

    Where's UserList.ListMixin?

    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.ListMi xin and maybe even UserString.Stri ngMixin 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
  • Raymond Hettinger

    #2
    Re: Where's UserList.ListMi xin?

    [Matthew Barnes][color=blue]
    > 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.ListMi xin and maybe even UserString.Stri ngMixin should have
    > followed (although I'm not sure how useful a StringMixin class would
    > really be).[/color]

    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_mont h.
    I think these classes are typical of objects that try to dynamically
    simulate list behavior.

    [color=blue]
    > Should I submit a patch?[/color]

    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 RichComparisonM ixin 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


    Comment

    Working...