A note about the ordering of mixin classes

In Python, when you have a class that inherits from both a primary class and some mixin classes (for example, if you're using the SocketServer stuff), it's conventional to declare your class's inheritance list with the primary class first:

class Real(primary, mixin1, mixin2):
    ....

However, an important safety tip: if your mixin class overrides methods of the primary class, it has to be first. Failure to observe this safety tip can cause head-scratching bugs followed by head-smacking embarrassment.

(Since I was mixing stuff in to standard types like list and tuple and str, I spent a certain amount of time wondering if the interpreter had special direct magic for them that meant I couldn't hijack and augment their standard behavior. I felt somewhat foolish when there turned out to be a much simpler explanation.)

These are my WanderingThoughts
(About the blog)

GettingAround
Full index of entries
Recent comments

This is part of CSpace, and is written by ChrisSiebenmann.

* * *

Atom feeds are available; see the bottom of most pages.

This is a DWiki.
(Help)

Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web

Search:
Written on 22 February 2007.
(Previous | Next)

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Feb 22 11:13:10 2007
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.