Syntax modification idea: (classmethods, properties locking...)

Arne Koewing ark at
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?

class bar(object):
    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 lockedwith(thelock):
	def wraper(lock,fun,arguments, keywords):
		print  lock + ".acquire()"
                    return fun(*arguments,**keywords)
			print lock + ".release()"
	return lambda fun:lambda  *args,**keys:wraper(thelock,fun,args,keys)
	#i think some object would be better... 
classic usage:
 >>> def g(arg):
	 print "working..."
 >>> stonelocked=lockedwith("stone")
 >>> g = stonelocked(g)

with syntax modification:

def g(arg) is lockedwith("stone"):
    #do stuff while keeping the lock...
    print "working..."

perhaps with the possibility to chain?
def quux(arg1) is staticmethod,lockedwith("token"):

what do you think? 


More information about the Python-list mailing list