Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56552
| From | Marco Buttu <marco.buttu@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: super in Python 3 and variadic arguments |
| Date | 2013-10-10 09:22 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <52565598.6000709@gmail.com> (permalink) |
| References | <l33tlf$rr1$1@speranza.aioe.org> <mailman.902.1381337680.18130.python-list@python.org> |
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 "<stdin>", line 1, in <module> >> File "<stdin>", 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 --> <frame object at 0x7f28cad4b240> So, why does not super use it? -- Marco Buttu
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-09 17:44 +0200
Re: super in Python 3 and variadic arguments Ned Batchelder <ned@nedbatchelder.com> - 2013-10-09 12:47 -0400
Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-10 09:22 +0200
Re: super in Python 3 and variadic arguments Ned Batchelder <ned@nedbatchelder.com> - 2013-10-10 07:04 -0400
Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-10 14:54 +0200
Re: super in Python 3 and variadic arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 02:11 +0000
Re: super in Python 3 and variadic arguments Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-10 20:33 -0600
Re: super in Python 3 and variadic arguments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 03:00 +0000
Re: super in Python 3 and variadic arguments Chris Angelico <rosuav@gmail.com> - 2013-10-11 17:08 +1100
Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-11 08:17 +0200
Re: super in Python 3 and variadic arguments Marco Buttu <marco.buttu@gmail.com> - 2013-10-11 08:15 +0200
csiph-web