New+old-style multiple inheritance

stephenpas at googlemail.com stephenpas at googlemail.com
Tue Dec 18 16:09:15 EST 2007


On Dec 18, 8:25 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Dec 18, 2:09 pm, Jonathan Gardner
>
>
>
> <jgardner.jonathangardner.... at gmail.com> wrote:
> > On Dec 18, 7:08 am, "stephen... at googlemail.com"
>
> > <stephen... at googlemail.com> wrote:
> > > We are trying to monkey-patch a third-party library that mixes new and
> > > old-style classes with multiple inheritance.  In so doing we have
> > > uncovered some unexpected behaviour:
>
> > <snip>
>
> > > I know this level of messing with python internals is a bit risky but
> > > I'm wondering why the above code doesn't work.
>
> > You've already discovered why--you're mixing old and new style
> > classes.
>
> > Monkey patching is definitely unpythonic. You must be a Ruby guy. Why
> > don't you try doing something else to get the behavior you want,
> > something more explicit?
>
> Time and place.
>
> A well-considered, timely monkey-patch can sometimes save all kinds of
> workarounds and other headaches.
>
> Carl Banks

Indeed, I chuckled at the idea I was a Ruby programmer.  Of course
it's a bit of a hack but monkey-patching has been common place in the
Zope world for years (maybe Zope3 has rid itself of the problem).

Agreed, mixing new and old-style classes in multiple inheritance is
asking for trouble (although the Guido's essay on the new-style
classes  suggests you can: http://www.python.org/download/releases/2.2.3/descrintro/#subclassing).
I won't name and shame the library involved but unfortunately we can't
always pick and choose the tools we work with unless we want to write
(or rewrite) everything ourselves.

Cheers,
Stephen.



More information about the Python-list mailing list