Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'argument': 0.05; 'classes,': 0.05; 'root': 0.05; 'tree': 0.05; 'subject:Python': 0.06; '(except': 0.07; 'remaining': 0.07; '__init__': 0.09; 'arguments': 0.09; 'arguments,': 0.09; 'meaningful': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'mostly': 0.14; "wouldn't": 0.14; 'posted': 0.15; "'''": 0.16; 'args,': 0.16; 'article.': 0.16; 'article:': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'conclusion:': 0.16; 'dictionary,': 0.16; 'inheritance': 0.16; 'merely': 0.16; 'positional': 0.16; 'simplified': 0.16; 'sorts': 0.16; 'subclass': 0.16; 'subclasses': 0.16; 'subject: \n ': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'url.': 0.16; 'write,': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'trying': 0.19; 'value.': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'stick': 0.24; 'subject:problem': 0.24; 'helpful': 0.24; 'versions': 0.24; 'cc:2**0': 0.24; 'shown': 0.26; 'second': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; '[1]': 0.29; 'generally': 0.29; 'related': 0.29; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; 'code': 0.31; '+0100,': 0.31; 'claiming': 0.31; "d'aprano": 0.31; 'explained': 0.31; 'keywords,': 0.31; 'steven': 0.31; 'url:05': 0.31; 'class': 0.32; 'probably': 0.32; 'are:': 0.33; 'comment': 0.34; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'advice': 0.35; 'classes': 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; "he's": 0.36; 'keyword': 0.36; 'done': 0.36; 'method': 0.36; 'useful': 0.36; 'should': 0.36; 'wrong': 0.37; 'two': 0.37; 'being': 0.38; 'whatever': 0.38; 'rather': 0.38; 'how': 0.40; 'even': 0.60; 'remove': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'eventually': 0.60; 'ian': 0.60; 'most': 0.60; 'no.': 0.61; 'strictly': 0.61; "you're": 0.61; 'first': 0.61; 'making': 0.63; 'name': 0.63; 'kind': 0.63; 'more': 0.64; 'forward': 0.65; 'linked': 0.65; 'needs,': 0.65; 'url:26': 0.68; 'url:2011': 0.75; 'article': 0.77; 'url:wordpress': 0.78; 'avoids': 0.84; 'dict.': 0.84; 'oscar': 0.84; 'subject: *': 0.84; 'subject:skip:o 10': 0.84; 'trick.': 0.84; 'dirty': 0.93; 'inheritance,': 0.93; 'technique': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=Mv7ngcmDIOLmvf7rQaQg2JqoI8kuf3kTegukql+1aY8=; b=T+RaCopjrk5MShZ7kQAQvcyD00VFw+YNSj3yutrzDrbw5oeHZkbr1FA9Dqui6fhTH4 rOoZuUggq/m/IXSn616gOnEcxI20MTLJs7rhi4/5vEPIXmEGLBhbyUmuh4qioNsuaogY JS5eHMlzUxtzgxel4e4U2c4a5C+A4crfObUlEMNzsTS6faMfRkqaOrPfPruRfwbxq6j1 XpaYi4GxDFV1WLVMglizWNYn7dS1RR2NYdvJZaHUMKA0pIzOyLVz8uDXYAGeGLkxqBLZ 6h9yDBXNfr6ZAWD99KJaEk+rD72ViGViE0Kj4SVPSGV7IWpKmvRtuhyRyn7JQlEhk7hY k6GQ== X-Received: by 10.52.16.76 with SMTP id e12mr4325295vdd.50.1368700288249; Thu, 16 May 2013 03:31:28 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51943f13$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <51943f13$0$29997$c3e8da3$5496439d@news.astraweb.com> From: Oscar Benjamin Date: Thu, 16 May 2013 11:31:08 +0100 Subject: Re: Python 2.7.x - problem with obejct.__init__() not accepting *args and **kwargs To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 93 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368700291 news.xs4all.nl 15925 [2001:888:2000:d::a6]:52266 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45418 On 16 May 2013 03:06, Steven D'Aprano wrote: > On Wed, 15 May 2013 13:16:09 +0100, Oscar Benjamin wrote: > > >> I don't generally use super() > > Then you should, especially in Python 3. > > If you're not using super in single-inheritance classes, then you're > merely making your own code harder to read and write, and unnecessarily > difficult for others to use with multiple-inheritance. > > If you're not using super in multiple-inheritance[1] classes, then your > code is probably buggy. > > There really is no good reason to avoid super in Python 3. I should have been clearer. I don't generally use super() because I don't generally use Python in a very object-oriented way. My comment was intended as a qualification of my advice rather than a suggestion that there is something wrong with super(). I can certainly see how that would be misinterpreted given the article I linked to: >> but I did see some advice about it in this article: >> https://fuhm.net/super-harmful/ > > It's not a good article. The article started off claiming that super was > harmful, hence the URL. He's had to back-pedal, and *hard*. The problem > isn't that super is harmful, it is that the problem being solved -- > generalized multiple inheritance -- is inherently a fiendishly difficult > problem to solve. Using super and cooperative multiple inheritance makes > it a merely difficult but tractable problem. > > The above article is useful to see the sorts of issues that can come up > in multiple inheritance, and perhaps as an argument for avoiding MI > (except in the tamed versions provided by mixins or straits). But as an > argument against super? No. I read that article when I was trying to do something with multiple inheritance. It was helpful to me at that time as it explained why whatever I was trying to do (I don't remember) was never really going to work. > > A much better article about super is: > > http://rhettinger.wordpress.com/2011/05/26/super-considered-super/ This is a good article and I read it after Ian posted it. > > >> From the conclusion: >> "Never use positional arguments in __init__ or __new__. Always use >> keyword args, and always call them as keywords, and always pass all >> keywords on to super." > > Even that advice is wrong. See Super Considered Super above. Raymond's two suggestions for signature are: ''' One approach is to stick with a fixed signature using positional arguments. This works well with methods like __setitem__ which have a fixed signature of two arguments, a key and a value. This technique is shown in the LoggingDict example where __setitem__ has the same signature in both LoggingDict and dict. A more flexible approach is to have every method in the ancestor tree cooperatively designed to accept keyword arguments and a keyword-arguments dictionary, to remove any arguments that it needs, and to forward the remaining arguments using **kwds, eventually leaving the dictionary empty for the final call in the chain. ''' The first cannot be used with object.__init__ and the second is not what the OP wants. I think from the article that the appropriate suggestion is to do precisely what the OP has done and make everything a subclass of a root class that has the appropriate signature. Perhaps instead of calling it my_object it could have a meaningful name related to what the subclasses are actually for and then it wouldn't seem so much like a dirty trick. > [1] To be precise: one can write mixin classes without super, and > strictly speaking mixins are a form of multiple inheritance, but it is a > simplified version of multiple inheritance that avoids most of the > complications. They're also mostly the only kind of multiple inheritance that I would think of using. Oscar