[ZODB-Dev] ZODB 3.2.4 strange getattr, hasattr behaviour
Syver Enstad
syver at inout.no
Wed Nov 24 07:49:09 EST 2004
"Tim Peters" <tim at zope.com> writes:
> The question I have is about "add one more occurrence ...": if this is
> something that routinely bites you, why do you create class data attributes?
I don't usually, but I tried it for a quick fix for a new attribute in
a Persistent class, since __getstate__ updating doesn't work in ZODB
(the _p_changed and so on). Actually it has only been one time
previous but that time confused me a lot too.
I did something like this (a couple of years ago):
class TheClass:
_attr = None
def myMethod(self):
if self._attr is None:
self._attr = SoAndSo
inst = TheClass()
inst.myMethod()
assert TheClass._attr == SoAndSo # this fails as I guess most of you know
So the case with my upgrade script just highlights that once more.
> Unlike class method attributes, class data attributes are almost never
> necessary. IOW, if punching yourself in the eye hurts, there are
> alternatives to wishing your knuckles were softer. For example, you could
> wish that your eye were harder <wink>.
The first thing I did after discovering what I had done was to get rid
of them by using an upgrade script instead.
More information about the ZODB-Dev
mailing list