I'm using the attrs
python package, in combination with inheritance and slots. I want to call the parent class's method from within the derived method. The problem is demonstrated below:
import attr
@attr.s(slots=True)
class Base():
def meth(self):
print("hello")
@attr.s(slots=True)
class Derived(Base):
def meth(self):
super().meth()
print("world")
d = Derived()
d.meth()
I get:
TypeError: super(type, obj): obj must be an instance or subtype of type
The problem seems to be triggered by a combination of attrs (undecorated classes with explicit __slots__=()
work), slots (regular @attr.s
-decorated classes work) and the plain super()
call (super(Derived, self)
works).
I would like to understand how super()
behaves differently from the explicit super(Derived, self)
version, since the documentation says they "do the same thing"