Skip to content

Instantly share code, notes, and snippets.

View ZeroICQ's full-sized avatar
🤖
Working from home

Alexey Mogilyovkin ZeroICQ

🤖
Working from home
View GitHub Profile
@ZeroICQ
ZeroICQ / property_inheritance.md
Created May 3, 2021 06:00 — forked from Susensio/property_inheritance.md
Inherit property setter in python 3.7

Python @property inheritance the right way

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:

  • Child redefines value property completely, both getter and setter.