Syntax modification idea: (classmethods, properties locking...)
ark at gmx.net
Thu Jan 16 22:03:12 CET 2003
After reading some treads about
"A Hygienic Macro System in Python"
i've had an idea:
why not extending the def statement?
def foo(class,arg1) is classmethod:
def bar(arg1) is staticmethod:
def X(...) is Y: #don't know if 'is' is realy a goog idea...
would define <<block>> as function (as usual)
and then pass it do Y (a callable) that may return
a modified version which will be assigned to X
let's try with an user-defined "pseudo-locking"
def wraper(lock,fun,arguments, keywords):
print lock + ".acquire()"
print lock + ".release()"
return lambda fun:lambda *args,**keys:wraper(thelock,fun,args,keys)
#i think some object would be better...
>>> def g(arg):
>>> g = stonelocked(g)
with syntax modification:
def g(arg) is lockedwith("stone"):
#do stuff while keeping the lock...
perhaps with the possibility to chain?
def quux(arg1) is staticmethod,lockedwith("token"):
what do you think?
More information about the Python-list