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 "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in bfoo
RuntimeError: super(): no arguments

How come?
--
Marco Buttu
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to