[Python-Dev] On decorators implementation
paolo_veronelli at libero.it
Mon Aug 22 10:12:46 CEST 2005
> I noticed (via using them) that decorations are applied to methods
> before they become methods.
> This choice flattens down the implementation to no differentiating
> methods from functions.
> I have to apply euristics on the wrapped function type when I use the
> function as an index key.
> if type(observed) is types.MethodType:
> things like this are inside my decorators.
> The behavior of decorations are not definable.
> I imagine that a method implementation of them inside the type metaclass
> could be better specified by people.
> This probably ends up in metamethods or something I can't grasp
A downside of decorating at function level is that it's virtually
impossible to check from the decorator that the first call parameter
(aka self) is an instance of the method class.This check must be done
inside the decorated.
This can really happen in normal use as decorators are useful to
register the decorated as a 'callback'.Who ever fires it can do it with
no respect on the class belonging of the function/method, and the
error raised will not be coherent with 'calling method on a incompatible
Maybe it's possible to let the decorator know the method class even if
the class is still undefined.(Just like recursive functions?)
This would allow decorators to call super with the right class also.
@callSuper decoration is something I really miss.
More information about the Python-Dev