Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'arguments': 0.05; 'subject:Python': 0.06; '>>>>': 0.09; 'args,': 0.09; 'arguments.': 0.09; 'dict': 0.09; 'foo': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'mutable': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'def': 0.12; 'wrote:': 0.14; '**kwargs)': 0.16; '**kwargs):': 0.16; 'called,': 0.16; 'in?': 0.16; 'kwargs.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'received:gateway01.websitewelcome.com': 0.16; 'subject:() ': 0.16; 'subject:considered': 0.16; 'super,': 0.16; 'argument': 0.16; 'traceback': 0.16; '(most': 0.16; 'keyword': 0.19; 'header :In-Reply-To:1': 0.21; 'last):': 0.23; 'wondered': 0.23; 'values': 0.25; 'pass': 0.27; 'instead': 0.29; 'booth': 0.30; 'typeerror:': 0.30; 'calling': 0.31; 'named': 0.32; 'steven': 0.32; 'to:addr :python-list': 0.33; 'error': 0.33; 'file': 0.34; 'fail': 0.34; 'header:User-Agent:1': 0.35; '"",': 0.35; "d'aprano": 0.35; 'realise': 0.35; 'probably': 0.36; 'subject:: ': 0.38; 'got': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.60; 'order': 0.62; 'subject:!': 0.67; 'received:websitewelcome.com': 0.67; 'supply': 0.69; 'injecting': 0.84; 'signature.': 0.84; 'trick,': 0.84 Date: Fri, 27 May 2011 10:42:16 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python's super() considered super! References: <1f0d88bd-e2e6-4780-9d9e-784fb3f53837@k3g2000prl.googlegroups.com> <87wrhcapm2.fsf@benfinney.id.au> <02172345-6f3b-4fc6-9b88-1c546e3e480a@k15g2000pri.googlegroups.com> <87boyoa5ov.fsf@benfinney.id.au> <4ddf7ed8$0$29996$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:1599 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 2 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 37 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306517378 news.xs4all.nl 49178 [::ffff:82.94.164.166]:45503 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6414 Duncan Booth wrote: > Steven D'Aprano wrote: > >> I was thrilled to learn a new trick, popping keyword arguments before >> calling super, and wondered why I hadn't thought of that myself. How on >> earth did I fail to realise that a kwarg dict was mutable and therefore >> you can remove keyword args, or inject new ones in? >> > Probably because most of the time it is better to avoid mutating kwargs. > Instead of popping an argument you simply declare it as a named argument in > the method signature. Instead of injecting new ones you can pass them as > named arguments. > > > def foo(x=None, **kwargs): > bar(y=2, **kwargs) > > > def bar(**kwargs): > print(kwargs) > >>>> foo(x=1, z=3) > {'y': 2, 'z': 3} >>>> foo(x=1, y=2, z=3) > Traceback (most recent call last): > File "", line 1, in > foo(x=1, y=2, z=3) > File "", line 2, in foo > bar(y=2, **kwargs) > TypeError: bar() got multiple values for keyword argument 'y' And the above error is exactly why you don't want to use named arguments in MI -- because you don't know in what order the methods will be called, you cannot know which named arguments to supply to the method that super() will call next. ~Ethan~