Needed: Real-world examples for Python's Cooperative Multiple Inheritance

Kirill Simonov xi at gamma.dn.ua
Mon Nov 29 10:00:48 EST 2010


Hi Raymond,

Another example: extensions in Mercurial.  Mercurial is a VCS with a 
typical command line syntax:

$ hg <command> <command arguments and options>

Mercurial has an extension mechanism for adding new and modifying 
existing commands.  A big chunk of Mercurial functionality is 
implemented in `ui` and `repo` classes and extensions often patch those 
to override the default behavior.  For instance, you could check the 
`color` extension, which patches `ui` to override `write*` methods:

http://selenic.com/hg/file/3790452d499b/hgext/color.py#l152


Thanks,
Kirill


On 11/24/2010 03:08 PM, Raymond Hettinger wrote:
> I'm writing-up more guidance on how to use super() and would like to
> point at some real-world Python examples of cooperative multiple
> inheritance.
>
> Google searches take me to old papers for C++ and Eiffel, but that
> don't seem to be relevant to most Python programmers (i.e. a
> WalkingMenu example where a submenu is both a Entry in a Menu and a
> Menu itself).  Another published example is in a graphic library where
> some widgets inherit GraphicalFeature methods such as location, size
> and NestingGroupingFeatures such as finding parents, siblings, and
> children.  I don't find either of those examples compelling because
> there is no particular reason that they would have to have overlapping
> method names.
>
> So far, the only situation I can find where method names necessarily
> overlap is for the basics like __init__(), close(), flush(), and
> save() where multiple parents need to have their own initialization
> and finalization.
>
> If you guys know of good examples, I would appreciate a link or a
> recap.
>
> Thanks,
>
>
> Raymond
>




More information about the Python-list mailing list