classic and property() version of same attribute - yikes!
skip at pobox.com
Wed Jul 14 14:38:16 EDT 2004
I just stumbled upon a bug in some group-written code. We have this sort of
self.attr = 0.0
def SetAttr(self, a):
self.attr = a
def set_attr(self, a):
attr = property(get_attr, set_attr, None, None)
Each of the four classes is defined in a different module. The author of A
was not aware that it was a new-style class and coded it like a classic
class. The author of C (different person) apparently knew it was new-style
and took advantage of that fact to use property(), but didn't notice there
was already an attribute named "attr" two levels up.
This of course all gets to the Zen bit: "Flat is better than nested", and
I'll use that as an argument for flatter hierarchies in the future.
Nonetheless, what would be the effect of such an attribute stomping? Do I
just have multiple ways to change self.attr, assuming __slots__ hasn't been
declared? This seems like something perhaps pychecker should notice, but
More information about the Python-list