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
--
https://mail.python.org/mailman/listinfo/python-list