getattr() woes
Aahz
aahz at pythoncraft.com
Tue Dec 28 23:06:47 EST 2004
In article <87hdm5hnet.fsf at thomas.local>,
Thomas Rast <foo.bar at freesurf.ch.invalid> wrote:
>
>I've found out about a fundamental problem of attribute lookup, the
>hard way.
Maybe.
>asyncore.py uses the following code:
>
>class dispatcher:
> # ...
> def __getattr__(self, attr):
> return getattr(self.socket, attr)
>
>Now suppose that I'm asking for some attribute not provided by
>dispatcher: The lookup mechanism will apparently try to find it
>directly and fail, generating an AttributeError; next it will call
>__getattr__ to find the attribute. So far, no problems.
>
>But I used a property much like this:
>
>>>> import asyncore
>>>> class Peer(asyncore.dispatcher):
>... def _get_foo(self):
>... # caused by a bug, several stack levels deeper
>... raise AttributeError('hidden!')
>... foo = property(_get_foo)
>...
You're not supposed to use properties with classic classes.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
More information about the Python-list
mailing list