Thinking about Python's inheritance modelI recently read an entry by someone who
was surprised that Python subclasses did not automatically call their
parent class's 'constructor' method, by which he meant The straightforward way to explain Python's inheritance model is that it uses what I could call 'lookup based' or 'name based' subclassing, where what subclassing does is change what binding will be returned when you look up a given name on an instance of the (sub)class. And that's pretty much it as for what subclassing does. (Technically subclassing has some additional effects when you use
The next thing to know is that all of Python's special operations,
including (Note that multiple inheritance does not preclude magic upcalls, since there is a defined method resolution order that the upcalling could follow.) One consequence of this simple model of subclassing is that you can
fake subclassed instances by using other methods
and outside people generally won't notice anything. (They can tell
if they use |
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |