[Tutor] Intercepting methods calls

Andreas Kostyrka andreas at kostyrka.org
Wed Jun 4 10:09:41 CEST 2008

On Wednesday 04 June 2008 07:41:49 Marilyn Davis wrote:
> On Tue, June 3, 2008 10:16 pm, Alan Gauld wrote:
> > "Laureano Arcanio" <listas.condhor at gmail.com> wrote
> >
> >> Is there any way to intercept calls to methods ? like the
> >> __setattribute__
> >> medthod does ?
> >
> > There are several variations on how to do that kind of thing.
> > Can you give us some more background on what you are
> > trying to achieve that makes you need to do that?
> Great question, Alan.  But, whatever the answer, I'd like to see the
> variations listed, if you have time.

Well, let's start the ball rolling then.


The basic working is that you've got a function, and that get's wrapped.

In the "normal case", the function is a (__get__ only) property, and this 
__get__ is what makes Bound/Unbound methods out of a function object.
(you can check it out, SomeClass.method versus SomeClass.__dict__["method"] 
versus SomeClass().method)

Now the above listing is basically a list of points were you can effect a 
change of behaviour.

One of the classical uses for that messy business is usually some kind of 
automatically constructed "proxy" class. (Proxy is rather general, e.g. RPC, 
or ORM classes come to mind)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/tutor/attachments/20080604/6568255e/attachment.pgp>

More information about the Tutor mailing list