[Python-3000] Give power to __getattr__
Nick Coghlan
ncoghlan at gmail.com
Wed Apr 26 13:02:56 CEST 2006
Kay Schluehr wrote:
> What I'm looking for is capturing the call of an arbitrary special
> method without implementing it explicitely. This would enable delegating
> a call on __add__ to another class that implements __add__. This could
> either be done by empowering __getattribute__ or use the now residual
> __getattr__ that has no value in case of an __getattribute__
> implementation. Of course if we are free to choose a name it would be
> better to use a non-confusing name e.g. __getspecialattr__ that is used
> when the attribute is the name of a special method and the method
> accordingly is neither an instance attribute nor could it be found in
> the class tree.
Ah, I see what you're getting at - currently the interpreter doesn't fall back
to the generic __getattribute__ slot for most special methods, so it makes it
harder to write proxy objects, and those proxy objects aren't future proof.
I suspect the right answer to that is to provide better metaprogramming tools
to make writing proxy objects easier, rather than providing additional
fallback paths for the special methods in the interpreter (as the latter slows
down the common case to benefit the comparatively rare case of proxying).
Exactly what those tools might be, I'm not sure :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list