Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'args': 0.07; 'method.': 0.07; '__init__': 0.09; 'arguments': 0.09; 'def': 0.12; '**kwargs):': 0.16; '23,': 0.16; 'bug,': 0.16; 'does,': 0.16; 'inheritance': 0.16; 'kwargs': 0.16; 'subject:object': 0.16; 'exception': 0.16; 'prevent': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'reporting': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'object.': 0.31; 'steven': 0.31; 'class': 0.32; 'probably': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'classes': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'keyword': 0.36; 'object,': 0.36; 'doing': 0.36; 'method': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'reaching': 0.61; "you're": 0.61; 'thing,': 0.91; 'technique': 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:from:date:message-id:subject:to :content-type; bh=klF9ErGvz4f8daVk/xeWAZ2XJYotr+Bu7JDjdTMje54=; b=pusWrAwPA9B4LN5KKA11PAuLTkU2/Lp/mYTYDMuNz4E1JGt11e+1V01JR/PjuhxoY6 Nzif1LxXP49/5en7ZW2xUpsPBH7u/nUOuitLYtHF/y6xZZ8H2JKOprYZW9w3RAQOZIGF Gux6BNLnskG1WwkSUl+h9Q9TL2obyQotoM+tD6W+2HcMUoKQQqfgVC70vLM5iYLEN/hm jxQESFaLgzt9bvJjH4F2+wCDC5c3MlmXS0ZWEgoxkeb31Kf41OrEGNdyGAXlXfMsRYld 4MJWxTuRtHDK0KaApXR3AviaBzI5yR97Uj0AATqa73ofIQbAc7UlHhVbbyKUCe6/Pdh1 boZg== X-Received: by 10.68.189.199 with SMTP id gk7mr10054438pbc.208.1372014369358; Sun, 23 Jun 2013 12:06:09 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51c7426f$0$29999$c3e8da3$5496439d@news.astraweb.com> 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> <51c7426f$0$29999$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sun, 23 Jun 2013 13:05:29 -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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372014378 news.xs4all.nl 15959 [2001:888:2000:d::a6]:56396 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49000 On Sun, Jun 23, 2013 at 12:46 PM, Steven D'Aprano wrote: > All is not lost, there are ways to make your classes cooperative. The > trick is to have your classes' __init__ methods ignore keyword arguments > they don't know what to do with. object used to do the same thing, but it > no longer does, so you need to add an extra class just before object to > swallow any args before they read object. > > > class Blocker(object): > def __init__(self, **kwargs): > # Block kwargs from reaching object > super(Blocker, self).__init__() I don't like the idea of doing this with a cooperative __init__ method. If any keyword arguments were passed that weren't consumed, that is probably a bug, and this just swallows the exception instead of reporting it. Of course, if you're doing cooperative inheritance with some other method that doesn't exist on object, then this technique is necessary to prevent the topmost class from trying to call that method on object and erroring out.