Overriding methods in classes you don't control

andybak at gmail.com andybak at gmail.com
Mon Mar 28 13:08:43 CEST 2005

I've also come across several situations where modifying existing
classes seems the simplest and most intuitive thing to do.

Obviously it is fine for quick hacks but people tend to go 'whoooooo'
and wave their fingers around when people suggest it as a general

Has anyone got any experience of doing this on medium-size projects and
how quickly things descend into an unmaintainable mess?

What are the specific problems and can they be avoided/worked around?

I suppose the main thing is the problems it causes for other people
reading your source code i.e. how are they supposed to know that Class
X now has some of your code  injected into it. And thinking about it.
How are you supposed to remember 3 months down the line!

Maybe a 'best practises' system where any such modifications were made
or mentioned right at the start of the source tree or in a distinctly
named module could alleviate this?

runsun pan wrote:
> Some untested idea:
> 1. find what is the base class of wxPython
> 2. x= subclass from that base class
> 3. make wxPython.__base__ = x
> Don't know if this works, but this is what I would try if I were u
> ('cos its ease).

More information about the Python-list mailing list