Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.fsmpi.rwth-aachen.de!news.unit0.net!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '(even': 0.05; 'differently': 0.07; 'method.': 0.07; 'suppose': 0.07; '22,': 0.09; 'methods,': 0.09; 'override': 0.09; 'python': 0.11; '__del__': 0.16; 'behave': 0.16; 'exceptions,': 0.16; 'garbage': 0.16; 'inconvenient': 0.16; 'magic': 0.16; 'new-style': 0.16; 'overridden': 0.16; 'overriding': 0.16; 'proxy,': 0.16; 'side.': 0.16; 'subject:object': 0.16; 'sat,': 0.16; ':-)': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'proxy': 0.24; 'simpler': 0.24; 'regardless': 0.24; 'header:In-Reply-To:1': 0.27; 'generally': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'about.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'implemented': 0.33; 'not.': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'could': 0.34; "can't": 0.35; 'classes': 0.35; 'something': 0.35; '(2)': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'curious': 0.36; 'doing': 0.36; 'method': 0.36; 'should': 0.36; 'wrong': 0.37; 'two': 0.37; 'implement': 0.38; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'bad': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; 'manually': 0.60; 'skip:* 10': 0.61; "you're": 0.61; 'first': 0.61; 'such': 0.63; 'provide': 0.64; 'more': 0.64; 'due': 0.66; 'delegate': 0.68; 'default': 0.69; 'calls,': 0.84; 'delegated': 0.84; 'hardly': 0.84; 'regard.': 0.84; 'troublesome': 0.91; '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:from:date:message-id:subject:to :content-type; bh=asSm6z8rFzUhsYhJSr39qlIijllBCXXL0qiOsSCpScs=; b=YAVwaIEyq+XCFf6Lvi6+0leYzfOQrA6+odIyZSh5oVM6vRVx/lxeJJtxThyCUnXWg3 k9IDEuKPvVMIHAC2+otHSwZZAVPccauuKdC1f211mXDOCZzCMRbnDWAWYXe/LQcruRfR plPDLGdrzwM9zGbRq0wb+PaT27x3WBTsFKpr6MmBg44HcurgKnGMy74Z/HnE1nrAuVE9 LGQlj46Tmq14RuAdmmY4PF4cPl6972YIqEcG4yHyPMcZJfBOJGJ9NnFs3zNBhWy1JyMH 4kAPAvSxZs3qi6IwIEgV1wD0jZeiVjXd0+2lE8gkx0dCxHYrlxNg5L6DHBaYbcuh1kHu GjQg== X-Received: by 10.66.146.9 with SMTP id sy9mr23051917pab.16.1371966093727; Sat, 22 Jun 2013 22:41:33 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51c68638$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <15ba0011-bbf1-42f7-b3ea-1c1d4b70e56b@googlegroups.com> <51c66962$0$29999$c3e8da3$5496439d@news.astraweb.com> <51c68638$0$29999$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sat, 22 Jun 2013 23:40:53 -0600 Subject: Re: What is the semantics meaning of 'object'? To: Python 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371967812 news.xs4all.nl 15975 [2001:888:2000:d::a6]:34291 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48978 On Sat, Jun 22, 2013 at 11:23 PM, Steven D'Aprano wrote: > On Sat, 22 Jun 2013 22:27:10 -0600, Ian Kelly wrote: >> I actually consider that an up side. Sure it's inconvenient that you >> can't delegate all such methods at once just by overriding >> __getattribute__, but it would be more troublesome to *accidentally* >> implement such methods because you implemented __getattribute__. > > It's hard to see a case where that would be a bad thing. > > 1) If the proxied object doesn't include __dunder__ methods, then the > proxy will just end up up calling the default object dunder methods, > exactly as if they weren't proxied. > > 2) If the proxied object does include dunders, then you generally want > the proxy to call them, with perhaps one or two exceptions, which need to > be overridden regardless of whether they are dunders or not. Proxying objects is not the only use of __getattribute__. >> And >> then there are methods that really should not be delegated in the first >> place, like __del__. > > If you're using __del__, you're probably doing something wrong :-) > > I suppose that __del__ is a good counter-example, but (1) hardly any > classes use __del__, and (2) for those that do, it's *way* simpler to > manually override __del__ in the proxy than to manually delegate every > dunder method you care about. There are typically a lot of dunder methods > you care about. If you manually override __del__ in the proxy, then as far as the garbage collector is concerned, your proxy object has a __del__ method (even if it does nothing), and so it will be treated differently from an object without a __del__ method. > It is not the case that dunder methods cannot be automatically proxied > because somebody deliberately designed Python to work that way. It's an > accidental side-effect of the way new-style classes resolve method calls, > due to decisions made for other reasons having nothing to do with > delegation. Can you elaborate or provide a link? I'm curious to know what other reason there could be for magic methods to behave differently from normal methods in this regard.