hasattr + __getattr__: I think this is Python bug

dmitrey dmitrey.kroshko at scipy.org
Tue Jul 20 06:10:25 EDT 2010


hi all,
I have a class (FuncDesigner oofun) that has no attribute "size", but
it is overloaded in __getattr__, so if someone invokes
"myObject.size", it is generated (as another oofun) and connected to
myObject as attribute.

So, when I invoke in other code part "hasattr(myObject, 'size')",
instead o returning True/False it goes to __getattr__ and starts
constructor for another one oofun, that wasn't intended behaviour.
Thus "hasattr(myObject, 'size')" always returns True. It prevents me
of some bonuses and new features to be done in FuncDesigner.

>>> 'size' in dir(b)
False
>>> hasattr(b,'size')
True
>>> 'size' in dir(b)
True

Could you fix it?



More information about the Python-list mailing list