fiddling a class's __bases__ attribute

Skip Montanaro skip at
Wed Sep 6 06:06:46 CEST 2000

I decided that for my CGI scripts I wanted FormContentDict objects to allow
items to be deleted, but I didn't want to create my own version of
just to add a __delitem__ method.  This was accomplished easily enough:

    class FormContentDictBase:
	def __delitem__(self,key):
	    del self.dict[key]

    import cgi
    FormContentDictBase.__bases__ = cgi.FormContentDict.__bases__
    cgi.FormContentDict.__bases__ = (FormContentDictBase,)

I'm pretty certain that __bases__ has been writable for awhile (since 1.5?).
Aside from the slight underhandedness of the technique is there anything
else I should be careful of?

By the way, has anyone else noticed that the Deja News search box on seems busted?  I searched there for __bases__
and got some hits pretty far afield from comp.lang.python
(alt.religion.kibology and sci.physics.relativity, to name two other

Skip Montanaro (skip at

More information about the Python-list mailing list