Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Marco Buttu Newsgroups: comp.lang.python Subject: Re: super in Python 3 and variadic arguments Date: Thu, 10 Oct 2013 09:22:00 +0200 Organization: Aioe.org NNTP Server Lines: 39 Message-ID: <52565598.6000709@gmail.com> References: NNTP-Posting-Host: yLEXU8HhfLiiXyuXjVRTFQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.python:56552 On 10/09/2013 06:47 PM, Ned Batchelder wrote: >> >>> 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 But is it a bug or the behavior we want? The first (implicit) argument is stored as expected as the first one in the args tuple, and the args tuple is inserted as expected in frame.f_locals: >>> import inspect >>> class B(A): ... def bfoo(*args): ... frame = inspect.currentframe() ... for obj, value in frame.f_locals.items(): ... print(obj, value, sep=' --> ') ... # super().afoo(*args[1:]) ... >>> B().bfoo(1, 2, 3) args --> (<__main__.B object at 0x7f28c960a590>, 1, 2, 3) frame --> So, why does not super use it? -- Marco Buttu