I'm curious on how inheritance works in case of dictionary mutations, I always thought that with each new instance the inherited classes get recreated.
class A(object):
test = {"B": 0}
def change_test(self, index):
self.test["B"] += index
def __init__(self, **kwargs):
self.change_test(self.index)
super(A, self).__init__(**kwargs)
class B(A):
index = 1
def print_test(self):
print self.test
class C(A):
index = 2
def print_test(self):
print self.test
b = B()
b.print_test()
c = C()
c.print_test()
Why does this return {'B': 1} {'B': 3} and not {'B': 1} {'B': 2}?