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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '__init__': 0.09; 'sep': 0.09; 'typeerror:': 0.09; 'def': 0.10; 'arbitrarily': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subclassing': 0.16; 'wrote:': 0.17; 'parameters': 0.20; 'received:209.85.214.174': 0.21; '"",': 0.22; 'logical': 0.22; 'work.': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; "d'aprano": 0.29; 'implies': 0.29; 'parameters.': 0.29; 'parent': 0.29; 'steven': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'code': 0.31; 'file': 0.32; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'subject:?': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'something': 0.35; 'add': 0.36; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'takes': 0.39; 'header:Received:5': 0.40; '30,': 0.62; '"just': 0.84; 'subject:always': 0.84; 'x):': 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=6zROBGfiX33N+BomR5vC2idsn2id7pFWt6K3LJmEQvw=; b=Yq5jKjQvZbgKvqlOHJz8TuHZKpUQToMeLr4lp9gpPW4z6bOjHZ1C+QUdTmR6qyhsdg shGUndXiEdwRJnQmvdPMqmTHt09gRBgvtamzP/90hFYMf2pV/qxysqq0aTkdVay5gMp+ P+VVV5zSA32junVmWdg9F2LSu4ErAwieoominfTKZ9dfv5j78jUeKx+3qrnUJDWE30TJ ik8sjC7BgobnqjWVujZs4YtI9wgcZZrNCLHZ4eCScZPSw1K5MbaYaQMeRr3pEjhw8I8s zUWNFd+IguSAHY+71xMyG3TWk6l9N+7h50zujkMP6iZuqynK0m7t1gi0Gzo7SOh7NADU WisA== MIME-Version: 1.0 In-Reply-To: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 30 Sep 2012 04:31:48 +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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348943511 news.xs4all.nl 6898 [2001:888:2000:d::a6]:50975 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30521 On Sun, Sep 30, 2012 at 3:17 AM, Steven D'Aprano wrote: > No. Only add code that works and that you need. Arbitrarily adding calls > to the superclasses "just in case" may not work: > > py> class Spam(object): > ... def __init__(self, x): > ... self.x = x > ... super(Spam, self).__init__(x) > ... > py> x = Spam(1) > Traceback (most recent call last): > File "", line 1, in > File "", line 4, in __init__ > TypeError: object.__init__() takes no parameters That's because you're subclassing something that doesn't take parameters and giving it parameters. Of course that won't work. The normal and logical thing to do is to pass on only the parameters that you know the parent class expects... but that implies knowing the parent, so it's kinda moot. ChrisA