Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Ron Garret
If I do this: def f(self): print self class c1: pass setattr(c1, 'm1', f) Then f is automagically transmogrified into the appropriate sort of method depending on how it is used: c1.m1 unbound method c1.f c1().m1 bound method c1.f of __main__.c1 instance at 0x51e738 c1().m1() __main__.c1

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Duncan Booth
Ron Garret [EMAIL PROTECTED] wrote: I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that prints debugging info before actually calling the old value of m1. The reason I want that to be an instance of a callable class instead of a function is that I need a place

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Michele Simionato
Duncan Booth wrote: Ron Garret [EMAIL PROTECTED] wrote: I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that prints debugging info before actually calling the old value of m1. The reason I want that to be an instance of a callable class instead of a function

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
Ron Garret wrote: The reason I want to do this is that I want to implement a trace facility that traces only specific class methods. I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that prints debugging info before actually calling the old value of m1. The reason

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
Ron Garret wrote: The reason I want to do this is that I want to implement a trace facility that traces only specific class methods. I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that prints debugging info before actually calling the old value of m1. The reason

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Ron Garret
In article [EMAIL PROTECTED], Kent Johnson [EMAIL PROTECTED] wrote: Ron Garret wrote: The reason I want to do this is that I want to implement a trace facility that traces only specific class methods. I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that

Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Ron Garret
In article [EMAIL PROTECTED], Michele Simionato [EMAIL PROTECTED] wrote: Duncan Booth wrote: Ron Garret [EMAIL PROTECTED] wrote: I want to say: trace(c1.m1) and have c1.m1 be replaced with a wrapper that prints debugging info before actually calling the old value of m1.