Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attribute': 0.07; 'think,': 0.07; '*args,': 0.09; 'calls.': 0.09; 'lookup': 0.09; 'methods,': 0.09; 'python': 0.11; 'def': 0.12; '(other': 0.16; '__init__,': 0.16; 'attributes,': 0.16; 'bugs.': 0.16; 'itself,': 0.16; 'kwargs': 0.16; 'lambda': 0.16; 'subclass': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'example': 0.22; "aren't": 0.24; "haven't": 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'restrict': 0.30; 'message- id:@mail.gmail.com': 0.30; 'getting': 0.31; '25,': 0.31; 'safely': 0.31; 'class': 0.32; 'not.': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'crazy': 0.36; 'method': 0.36; 'possible': 0.36; 'should': 0.36; 'work?': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; "you're": 0.61; 'happen': 0.63; 'between': 0.67; 'yourself': 0.78; '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=A0Kg7SuC90INoYJwUO3R0458ZDkRNWmL6PIl1MOBtZc=; b=KyscdcJ8/FLws7LVbL36ZhDDcW3o+de6xCN8J5noB7wQZYGUD/sfMYbanqO1z8HRS9 KkqBWqvv9YvbYr5m+3U/nkZLu0vs+N0a7KSQdUys2PrxEGDB95bfnwefkqMUHxpNsz75 Ed7AdUOnHgLzeLguk9lUQ1Nq4pVR+MV+1AvA6U7zxwOiVGTR81ZIt0f0kwxHmkG3BwCO 1ADcjtmL5cY0ms7kPdMPLL70HFWjAFq20JY6c35H1im68uYI6izbYQ3nG5DHc68YpTvq A8mEUlx6zk4c8eL0GHbLudAbGSe4583UdulWFCB2M6lkrUIkTeSanwMmVc9iC7fsKfY+ JC1w== X-Received: by 10.68.189.199 with SMTP id gk7mr978857pbc.208.1372199191205; Tue, 25 Jun 2013 15:26:31 -0700 (PDT) MIME-Version: 1.0 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> From: Ian Kelly Date: Tue, 25 Jun 2013 16:25:51 -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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372199201 news.xs4all.nl 15981 [2001:888:2000:d::a6]:54372 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49196 On Tue, Jun 25, 2013 at 4:17 PM, Chris Angelico wrote: > 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? class BlackHole(object): def __getattr__(self, attr): return lambda *args, **kwargs: None There's no way to restrict it to just methods, because there's no fundamental difference in Python between methods and other attributes, and at the point that you're looking it up you have no way of knowing whether the result is about to be called or not. And even if there were, this would be an excellent way to hide bugs.