Simple example Parent is class with version attribute. I want to inherit from this class but avoid sharing versions attribute among all inherited classes.
class Parent(object):
versions = []
@classmethod
def add_version(cls, version):
cls.versions.append(version)
class P1(Parent):
pass
class P2(Parent):
pass
class Thing(object):
pass
P1.add_version(Thing)
# should be Thing
print(P1.versions)
# should be empty [] by my design but it works other way in Python
# how to achieve to different versions fields without coding it in child classes?
print(P2.versions)
Produce such result since version is shared between classes - how to avoid?
[<class '__main__.Thing'>]
[<class '__main__.Thing'>]