Given a Parent class with value property, Child can inherit and overload the property while accessing Parent property getter and setter.
Although we could just reimplement the Child.value property logic completely without using Parent.value whatsover, this would violate the DRY principle and, more important, it wouldn't allow for proper multiple inheritance (as show in the example property_inheritance.py bellow).
Two options:
-
Childredefinesvalueproperty completely, both getter and setter. -
ChildusesParent.valueproperty, and only overloads setter.Parentclass must be referenced explicitly.
In either pattern, using Parent.value.getter is as simple as
return super().valueHowever, accessing Parent.property.setter is more verbose:
super(Child, type(self)).value.fset(self, new_value)It would be nice to just super().value = new_value but this won't work due to super current implementation (as Python 3.7).
There is a Python Issue regarding this rather unintuitive behaviour.
super(type(self), type(self)).setter.fset(self, value)doesn't follow mro adequately (because of the secondtype(self)).Check my solution: https://gist.github.com/willrazen/bef3fcb26a83dffb6692e5e10d3e67ac
Usage:
duper(super()).setter = value