I have classes, sharing the same property with the same getters, but different setters. As a simple, useless example, something like:
class Spam():
@property
def foo(self):
return self.bar
@foo.setter
def foo(self, foo):
self.bar = foo
class Eggs(Spam):
@foo.setter
def foo(self, foo):
self.bar = ' '.join(['Egg\'s foo:', foo])
Trying to run this module however throws the following error:
Traceback (most recent call last):
File "./test.py", line 13, in <module>
class Eggs(Spam):
File "./test.py", line 14, in Eggs
@foo.setter
NameError: name 'foo' is not defined
To make this work as desired, I need to re-define Eggs.foo
:
class Eggs(Spam):
@property
def foo(self):
return super().foo
@foo.setter
def foo(self, foo):
self.bar = ' '.join(['Egg\'s foo:', foo])
Is there a way to avoid this re-definition of the property? Since this is very annoying if you have lots of getters and setters like this in several sub-classes like I do.