[Compiler-sig] __getattr__ inflexibility
Thomas Heller
thomas.heller@ion-tof.com
Fri, 31 Mar 2000 21:48:45 +0200
> I was wondering about the __getattr__-built-in method. Currently it is
> called only if the attribute could not be found in the instance dictionary.
> Would it not be more flexible to -always- call it upon referencing an
> attribute, thus allowing programmers to override the default behaviour of
> simply returning the value matching the name (for example, the instance
> could dispatch an event before returning the value, or update it from an
> outside source). What I'm missing in Python is a feature to define derived
> member fields that don't simply contain static values, but rather dynamic
> ones (like method return values) but in every other respect behave like a
> normal member (included in the dir() listing, but referenced without using
> parentheses).
This could be achieved by simply allowing mapping objects instead of only
dictionaries. As I pointed out in a post to python-dev,
(see http://www.python.org/pipermail/python-dev/2000-March/004448.html)
the changes to Objects/classobject.c would be very small and would have
nearly no impact on performance.
The requirements I have are somewhat similar the what you describe.
Thomas Heller