
KISS (Keep It Simple, Super)
June 28, 2008Remember this?
I start cussing every time I come across that post
Not to say it’s not a great post, going to the trouble of writing all that down in such a lucid, careful manner was positively a service to the rest of us. Thanks, Foom.
It’s just that, the whole thing with super is so broken. Which brings to mind a conversation over sushi, about Python:
Friend: “Oh, that scripting language. Yeah I remember that, man that’s got such a broken object model.”
Me: (Squirms)
There wasn’t really much to say, was there? Super, new-style classes vs. old-style classes, can’t raise new-style objects, yada yada yada? Aieh…
End rant. What really I wanted to do here is write down the condensed version of Fuhm’s post, as a series of simple rules I can go back to. Here goes -
- Don’t mix regular classes with exception classes
- All regular classes should be new-style, derived from object
- They should have the constructor signature __init__(self, **kwargs)
- Every such __init__ invokes super(ClassName, self).__init__(**kwargs)
- Never extend a new-style class that doesn’t follow these rules
- Don’t use multiple inheritance for exceptions