Descriptor/Decorator challenge
Arnaud Delobelle
arnodel at googlemail.com
Tue Mar 6 14:44:48 EST 2007
On 5 Mar, 18:59, "Arnaud Delobelle" <arno... at googlemail.com> wrote:
[snip]
> Well in fact I couldn't help but try to improve it a bit. Objects now
> don't need a callerclass attribute, instead all necessary info is
> stored in a global __callerclass__. Bits that didn't work now do.
OK that wasn't really thought through. Because I changed the design
mid-way through writing it __callerclass__ wasn't doing the right
thing. I've sorted the issues I could see and made it (hopefully)
thread-safe. I'm not going to pollute this list again with my code so
I've put it at the following address:
http://marooned.org.uk/local.py
The problem is that all normal functions need to be decorated with
'@function' for it to work completely: if I understand correctly the
snippet below should raise an exception. It only does so if 'f' is
decorated with '@function' as below.
----------
@function
def f(x):
x.l()
class C(Object):
@localmethod
def l(self):
print "Shouldn't get here"
def v(self):
return f(self)
C().v() # Raises LocalMethod exception
----------
PS: in fact I'm not sure it's a good idea to decorate local methods:
what about local attributes which are not methods? They have to be
treated differently as only functions can be decorated.
What about functions / classes which are local to a module?
--
Arnaud
More information about the Python-list
mailing list