Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6414

Re: Python's super() considered super!

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 <ethan@stoneleaf.us>
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 <ethan@stoneleaf.us>
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> <Xns9EF278E61F5E6duncanbooth@127.0.0.1>
In-Reply-To <Xns9EF278E61F5E6duncanbooth@127.0.0.1>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2156.1306517378.9059.python-list@python.org> (permalink)
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

Show key headers only | View raw


Duncan Booth wrote:
> Steven D'Aprano <steve+comp.lang.python@pearwood.info> 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 "<pyshell#8>", line 1, in <module>
>     foo(x=1, y=2, z=3)
>   File "<pyshell#4>", 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~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python's super() considered super! Raymond Hettinger <python@rcn.com> - 2011-05-26 09:31 -0700
  Re: Python's super() considered super! Raymond Hettinger <python@rcn.com> - 2011-05-26 09:39 -0700
    Re: Python's super() considered super! Dotan Cohen <dotancohen@gmail.com> - 2011-05-26 21:13 +0300
    Re: Python's super() considered super! Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-26 12:38 -0600
    Re: Python's super() considered super! Dotan Cohen <dotancohen@gmail.com> - 2011-05-26 21:56 +0300
    Re: Python's super() considered super! Terry Reedy <tjreedy@udel.edu> - 2011-05-26 16:15 -0400
  Re: Python's super() considered super! Ben Finney <ben+python@benfinney.id.au> - 2011-05-27 11:39 +1000
    Re: Python's super() considered super! Raymond Hettinger <python@rcn.com> - 2011-05-27 00:16 -0700
      Re: Python's super() considered super! Ben Finney <ben+python@benfinney.id.au> - 2011-05-27 18:49 +1000
        Re: Python's super() considered super! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 10:37 +0000
          Re: Python's super() considered super! Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-27 10:53 +0000
            Re: Python's super() considered super! Ethan Furman <ethan@stoneleaf.us> - 2011-05-27 10:42 -0700
              Re: Python's super() considered super! Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-30 09:18 +0000
    RE: Python's super() considered super! "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-27 14:10 -0400
    Re: Python's super() considered super! Chris Angelico <rosuav@gmail.com> - 2011-05-28 04:40 +1000
  Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 07:27 -0700
    Re: Python's super() considered super! Mel <mwilson@the-wire.com> - 2011-05-27 10:33 -0400
      Re: Python's super() considered super! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 14:49 +0000
        Re: Python's super() considered super! harrismh777 <harrismh777@charter.net> - 2011-05-27 10:07 -0500
    Re: Python's super() considered super! Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-27 15:05 +0000
      Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 08:24 -0700
      Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 08:31 -0700
        Re: Python's super() considered super! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 16:06 +0000
          Re: Python's super() considered super! Stefan Behnel <stefan_ml@behnel.de> - 2011-05-27 23:49 +0200
            Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 16:57 -0700
              Re: Python's super() considered super! Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-28 07:29 +0200
          Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 17:04 -0700
      Re: Python's super() considered super! Ryan Kelly <ryan@rfk.id.au> - 2011-05-28 09:57 +1000
    Re: Python's super() considered super! sturlamolden <sturlamolden@yahoo.no> - 2011-05-27 08:11 -0700
  Re: Python's super() considered super! Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-27 12:31 -0600
  Re: Python's super() considered super! Chris Angelico <rosuav@gmail.com> - 2011-05-28 04:46 +1000
    Re: Python's super() considered super! John Nagle <nagle@animats.com> - 2011-05-27 13:47 -0700
  Re: Python's super() considered super! Ethan Furman <ethan@stoneleaf.us> - 2011-05-27 15:24 -0700

csiph-web