Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.05; 'subject:Python': 0.06; 'arguments': 0.09; 'way:': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'stored': 0.12; '*args': 0.16; '*args):': 0.16; 'class:': 0.16; 'inspects': 0.16; 'marco': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'environment': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'code': 0.31; '"",': 0.31; 'object.': 0.31; 'file': 0.32; 'class': 0.32; 'regular': 0.32; '(most': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'entry': 0.36; 'recent': 0.39; 'does': 0.39; 'how': 0.40; 'first': 0.61; 'name': 0.63; 'to:addr:gmail.com': 0.65; 'determine': 0.67; '11:44': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=+leoqtskhmM4RAhq4taeATMt9As5B+W+c0TLcFBZ+Ns=; b=0c//9aD+A/NtWf8DFz8K6Mur5ph9x/KTIHlE0y621t2BpI1kdGlvuX0KV/7RJ8pO+t fjFBl9FZWWREPe1Jd/r8HLoD/BcxNL62H7tURg9XFlg0Hwx4XQa9yUu2c3qUEVFLvwgN cpdx5Ozafgtb5/VetYuAyPXFc0woPzjswbBsild04FvA5Yk1ZWtlz1Paa4O+np7RXVVr Qks55r+3djHL14xeKaawMYw3SD8a4LVcyUq7z5xfIYOQ1DYHo5AFQJIeSljEIfu9J/KV ZF8auJUZ3urdPO9FXOgg1sfUsGuC+JTL/KAzOjzpJBJ0+gv/0lWnx4EOpnMV5dTVVf8u X9DQ== X-Received: by 10.221.40.10 with SMTP id to10mr6329401vcb.22.1381337234772; Wed, 09 Oct 2013 09:47:14 -0700 (PDT) Sender: Ned Batchelder Date: Wed, 09 Oct 2013 12:47:13 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Marco Buttu Subject: Re: super in Python 3 and variadic arguments References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381337680 news.xs4all.nl 15944 [2001:888:2000:d::a6]:49133 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56504 On 10/9/13 11:44 AM, Marco Buttu wrote: > Given this class: > > >>> class A: > ... def afoo(*args): > ... print(args) > > in Python 3 we can write the following class: > > >>> class B(A): > ... def bfoo(*args): > ... super(B, args[0]).afoo(*args[1:]) > ... > >>> B().bfoo(1, 2, 3) > (<__main__.B object at 0x7f5b3bde48d0>, 1, 2, 3) > > > without giving arguments to super, in this way: > > >>> class B(A): > ... def bfoo(self, *args): > ... super().afoo(*args) > ... > >>> B().bfoo(1, 2, 3) > (<__main__.B object at 0x7f5b3bdea0d0>, 1, 2, 3) > > But it does not work in this case: > > >>> class B(A): > ... def bfoo(*args): > ... super().afoo(*args[1:]) > ... > >>> B().bfoo(1, 2, 3) > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in bfoo > RuntimeError: super(): no arguments > > How come? The no-args super() call inspects the calling environment to determine the class and self. "self" is the first local name stored in frame.f_code.co_localsplus, but *args doesn't put "args" into that entry of the code object. Basically, super() is looking for the first regular argument in the function. --Ned.