Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'arguments': 0.07; 'dict': 0.09; 'sep': 0.09; 'subclass': 0.09; 'substitution': 0.09; '*always*': 0.16; 'caring': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'overriding': 0.16; 'subclassing': 0.16; 'substitute': 0.16; 'wrote:': 0.17; 'equivalent': 0.20; 'changes,': 0.23; 'class.': 0.23; 'command': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'concern': 0.29; "d'aprano": 0.29; 'hash': 0.29; 'parent': 0.29; 'steven': 0.29; 'class': 0.29; "i'm": 0.29; 'classes': 0.30; 'point': 0.31; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'received:209': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; '30,': 0.62; 'details': 0.63; 'details,': 0.65; 'yourself': 0.77; '"just': 0.84; 'subject:always': 0.84; 'subject:add': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=3QtR+x50KKtKkRg96C/pd7ywz4Odozhdxlbc7lw0kfI=; b=jbC0a9H1bayx536LPIDk6K7Z7uDqDC01s7qRhgHsQdwzNERYDKDu4Ckz7JBj7ErUn+ OveRpfNoTx/zuPYejXEIVZiurjiqiQWJa8+Xi2BevfBaaRNU/oV7P4Xxi32qz3M2Lc7T AGj86ThZ01YxSC9zV4OQtdYHEz8T/iNJXQGo+pGaEdN2PGZf/amTd1RlBH51ZIPlstv0 bo8v75t707wwJ2QZR/aov+/s5rtdLYHEIPqioa0M9/IZBPJcuLu7vcsS1w6IDGFeosXZ odoE1acGQZPmZxrE02J0NvYJM6TJMI6++ABpSGlCWm9DNWwJVN28hVz8A8BCXOtJCfw6 D3uA== MIME-Version: 1.0 In-Reply-To: <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> <5067cc81$0$29981$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 30 Sep 2012 14:53:09 +1000 Subject: Re: Should one always add super().__init__() to the __init__? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348980792 news.xs4all.nl 6866 [2001:888:2000:d::a6]:57595 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30540 On Sun, Sep 30, 2012 at 2:37 PM, Steven D'Aprano wrote: > Which is exactly my point -- you can't call the superclass "just in case" > it changes, because you don't know what arguments the new superclass or > classes expect. You have to tailor the arguments to what the parent > expects, and even whether or not you have to call super at all.[1] > > super() is not some magic command "don't bother me with the details, just > make method overriding work". You have to actually think about what you > are overriding. Yeah. Far as I'm concerned, subclassing should *always* involve knowing the parent class. You needn't concern yourself with its implementation (I can subclass dict without caring about the details of hash randomization), but you have to be aware of its interface. And if you change the base class without changing your method chaining, you'd better be changing to a new base class that's equivalent to the old one. The advantage of super() is that you can substitute a subclass of X as a new base class without changing anything. But you need to be sure that the replacement base class obeys the Liskov Substitution Principle. ChrisA