Dan Stromberg <drsali...@gmail.com> writes:
> Is there a way of decorating method1 of class C using method2 of class
Can you give a concrete example (i.e. not merely hypothetical) where
this would be a useful feature (i.e. an actual improvement over the
absence of the feature), and why?
> It seems like there's a chicken-and-the-egg problem; the class doesn't
> seem to know what "self" is until later in execution so there's
> apparently no way to specify @self.method2 when def'ing method1.
You're referring specifically to instance methods, it seems. Right,
there's no instance *of* the class during the *definition* of the class,
so ‘self’ can't refer to such an instance.
Also, an instance method needs to get the instance as the first
parameter, whereas the decorator must accept the to-be-decorated
function as its argument.
So I don't see what you're trying to achieve, rather than the more
straightforward and clearer use of a decorator function which *isn't* a
method in the same class.
Can you show a Simple, Self-Contained Complete Example to show us what
you're trying to do? More importantly, why you think it should be done
\ “Visitors are expected to complain at the office between the |
`\ hours of 9 and 11 a.m. daily.” —hotel, Athens |