Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'attribute': 0.07; 'think,': 0.07; 'calls.': 0.09; 'lookup': 0.09; 'python': 0.11; 'def': 0.12; "'%s(%r)'": 0.16; '(other': 0.16; '23,': 0.16; '__init__,': 0.16; 'be:': 0.16; 'collections': 0.16; 'does,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignoring': 0.16; 'inheritance': 0.16; 'itself,': 0.16; 'kwargs': 0.16; 'list):': 0.16; 'ordereddict': 0.16; 'remembers': 0.16; 'simplicity,': 0.16; 'subclass': 0.16; 'subject:object': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'wed,': 0.18; 'basically': 0.19; '>>>': 0.22; 'code,': 0.22; 'example': 0.22; 'import': 0.22; 'previously': 0.22; "aren't": 0.24; "haven't": 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'cool': 0.30; 'raymond': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '(which': 0.31; 'getting': 0.31; '3.2': 0.31; 'changed.': 0.31; "d'aprano": 0.31; 'noted': 0.31; 'overhead': 0.31; 'safely': 0.31; 'steven': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'advice': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'crazy': 0.36; 'false': 0.36; 'done': 0.36; 'method': 0.36; 'possible': 0.36; 'should': 0.36; 'level': 0.37; 'skip:o 20': 0.38; 'work?': 0.38; 'whatever': 0.38; 'to:addr :python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'release': 0.40; 'how': 0.40; 'ian': 0.60; 'first': 0.61; 'save': 0.62; 'complete': 0.62; 'show': 0.63; 'kind': 0.63; 'happen': 0.63; '26,': 0.68; 'saw': 0.77; 'yourself': 0.78; 'article,': 0.84; 'pardon': 0.84; 'inheritance,': 0.93; '2013': 0.98 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=v8cLKHxy16MzsGiyFxpqiqe5xIFRwxR2q6OdVYHhix4=; b=GcxpalHfS3x3KlNYzjYZTV4DGcVAsUd2kSUznesWgTlqxblJMS/Xr/6SpQUn84uDpA R87sr6K7CmGUjSRD/wPFvMVxABgX0fty/whrP/1W1yd0ME2Bx9Cz11wsr+np6Ni7glhd +0/mE34RFivhojChr6GsASYB/z6UCAOD2ihfsn9JqNlZoVAo82uoXebYwucrrkfdppus keC4dW9uvht/RlU3B9W5i0rE9m/Rl6tS1C+GhNqzKbfN5osL44axZNoM+AOoT048Lm5G QKNHBp1nCTeH29r43bxNRtB4ml1ZGvEOuwaqVFwbO/o6wepp+1SCcbfBMNjtaPwCvneJ nswQ== MIME-Version: 1.0 X-Received: by 10.52.120.77 with SMTP id la13mr564414vdb.23.1372198660418; Tue, 25 Jun 2013 15:17:40 -0700 (PDT) In-Reply-To: References: <15ba0011-bbf1-42f7-b3ea-1c1d4b70e56b@googlegroups.com> <51c66962$0$29999$c3e8da3$5496439d@news.astraweb.com> <20130623133546.GA2308@capricorn> <51c723b4$0$29999$c3e8da3$5496439d@news.astraweb.com> <51C74D6E.6030200@rece.vub.ac.be> Date: Wed, 26 Jun 2013 08:17:40 +1000 Subject: Re: What is the semantics meaning of 'object'? 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372198663 news.xs4all.nl 15890 [2001:888:2000:d::a6]:46227 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49192 On Wed, Jun 26, 2013 at 3:44 AM, Ian Kelly wrote: > On Sun, Jun 23, 2013 at 1:33 PM, Antoon Pardon > wrote: >> Op 23-06-13 18:35, Steven D'Aprano schreef: >>> Please don't. This is false economy. The time you save will be trivial, >>> the overhead of inheritance is not going to be the bottleneck in your >>> code, and by ignoring super, you only accomplish one thing: >>> >>> - if you use your class in multiple inheritance, it will be buggy. >> >> >> Which is why I don't understand that the python standard library still >> contains that kind of code. At least it did in 3.2 and I saw nothing >> in the 3.3 release notes that would make me suspect this has changed. > > This bothers me as well. If you look at Raymond Hettinger's "super() > considered super" article, he includes the (correct) advice that > super() needs to be used at every level of the call chain. At the end > of the article, he offers this example to show how "easy" multiple > inheritance can be: > > from collections import Counter, OrderedDict > > class OrderedCounter(Counter, OrderedDict): > 'Counter that remembers the order elements are first seen' > def __repr__(self): > return '%s(%r)' % (self.__class__.__name__, > OrderedDict(self)) > def __reduce__(self): > return self.__class__, (OrderedDict(self),) > > oc = OrderedCounter('abracadabra') > > Which is pretty cool in its simplicity, but here's the rub (which I > have previously noted on this list): OrderedDict doesn't use super. > Counter does, but not cooperatively; it just calls super().__init__() > with no arguments. So the fact that this example works at all is > basically luck. The main problem is getting to the top/end of the call chain. Classic example is with __init__, but the same problem can also happen with other calls. Just a crazy theory, but would it be possible to construct a black-holing object that, for any given method name, returns a dummy function that ignores its args? (Other forms of attribute lookup aren't going to be a problem, I think, so this can be just methods/functions.) Then you just subclass from that all the time, instead of from object itself, and you should be able to safely call super's methods with whatever kwargs you haven't yourself processed. Would that work? Caveat: I have not done much with MI in Python, so my idea may be complete balderdash. ChrisA