[PEAK] Inheritance and @when from PEAK-rules

PJ Eby pje at telecommunity.com
Mon Jul 16 14:07:15 EDT 2012


On Mon, Jul 16, 2012 at 12:56 PM, Athanasios Anastasiou
<athanasios.anastasiou at plymouth.ac.uk> wrote:
> Hello everyone
>
> I have been using PEAK-rules with functions but i came across some strange
> behaviour when it came to using it with classes and inherited methods.
>
> The problem (in one line) is that i find it difficult to get @when to call
> the "right" (overriden) function.

If you want to use generic functions as methods, you must use
@when(BaseClass.methodName.im_func) when defining overrides in a
subclass.  (Otherwise, your new method either will be called in place
of the generic function (if named the same) or it will not be called
at all (if it has a different name).

And, if you want that method to be able to call previous methods, use
the next_method machinery, not super().  (Otherwise, you will simply
call the same generic function a second time!)


More information about the PEAK mailing list