Re: Inheritance and @when from PEAK-rules
PJ Eby <pje-Wh6+Hckhi6HFNGf7iClzIwC/[email protected]> Mon, 16 Jul 2012 14:07:15 -0400
| Newsgroups | gmane.comp.python.peak |
|---|---|
| Message-ID | <CALeMXf4ZFnhWXAfvS+Wujmo8EWsMBxDRQOorwd8xDGj6QRiH3A@mail.gmail.com> |
On Mon, Jul 16, 2012 at 12:56 PM, Athanasios Anastasiou <[email protected]> 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!)