I want two class. Class A with a default class attribute and class B (child class) who override this class attribute. But if A class attribute definition is changed by developper, i don't want to write again B class attribute.
Exemple: With simple override:
class Animal:
actions = {}
class Dog(Animal):
actions = {'bite': 1}
If a day, Animal
is modified like this:
class Animal:
actions = {'bleed': 1}
Dog class have to be rewrited. So i do that to prevent parent class update:
Python 3.4.0 (default, Apr 11 2014, 13:05:18)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... d = {}
... @classmethod
... def c(cls):
... print(cls.d)
...
>>> class B(A):
... d = A.d.copy()
... d.update({0: 1})
...
>>> B.c()
{0: 1}
>>> A.c()
{}
Is this a good way to do it? Or is there a more "python way" to do it?