Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '__init__': 0.09; 'received :mail-qc0-f174.google.com': 0.09; 'sep': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'sat,': 0.15; 'arbitrarily': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.17; 'parameters': 0.20; '"",': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; "d'aprano": 0.29; 'leaves': 0.29; 'steven': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'code': 0.31; 'file': 0.32; 'traceback': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'takes': 0.39; 'header:Received:5': 0.40; 'gone': 0.64; 'potentially': 0.66; '"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:from:date:message-id:subject:to :cc:content-type; bh=QbFoxEeNv9ymXxHXC7gBF1RhQpP0MXGpQ9hUarp/fxQ=; b=kJE58djBXZDArukRSEhDtP8p3jaOSjNfU9dE79GSV+jJ9sOEhgcAYOpKH4rY3FEd6w B9EFLe9SwJFZRP9c68ZfSLRWwQ7srUbM/SCdyVwiXIRDB1A2liI6NFpawn5ubIq59QzR R0rhxibRv4MZUfcl9CXQQnyUR4Ii4E0w67Lrnb1PnuxX5F1RH/jrL17MxN2t+UGRmsJJ TkkXmc1QLdC2qQNdjwAZIxs/roa418J5tl4H3G1TxGy1hjAbza502mv4dNzBJRbyXMwE MEAa2E1nq3uSZ8goKwcmTvPIV7twJbvm99xHk3S47I8JtBjuio5t8yjvApFXbpjskBTV +5+A== MIME-Version: 1.0 In-Reply-To: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <50672d20$0$29981$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Sat, 29 Sep 2012 14:18:03 -0400 Subject: Re: Should one always add super().__init__() to the __init__? To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348942728 news.xs4all.nl 6963 [2001:888:2000:d::a6]:45747 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30520 On Sat, Sep 29, 2012 at 1:17 PM, 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 a good thing. We've gone from code that doesn't call the initializer and leaves the object in a potentially invalid state (silently!), to code that calls the initializer and then fails (loudly). -- Devin