In python 2.x, super accepts the following cases
class super(object)
| super(type) -> unbound super object
| super(type, obj) -> bound super object; requires isinstance(obj, type)
| super(type, type2) -> bound super object; requires issubclass(type2, type)
| Typical use to call a cooperative superclass method:
as far as I see, super is a class, wrapping the type and (eventually) the instance to resolve the superclass of a class.
I'm rather puzzled by a couple of things:
- why there is also no
super(instance)
, with typical usage e.g.super(self).__init__()
. Technically, you can obtain the type of an object from the object itself, so the current strategysuper(ClassType, self).__init__()
is kind of redundant. I assume compatibility issues with old-style classes, or multiple inheritance, but I'd like to hear your point. - why, on the other hand, python 3 will accept (see http://stackoverflow.com/questions/576169/python-super)
super().__init__()
? I see kind of magic in this, violating the explicit is better than implicit Zen. I would have seen more appropriateself.super().__init__()
.