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

Arne Koewing ark at gmx.net
Thu Jan 16 22:03:12 CET 2003


Hi!
After reading some treads about 
"A Hygienic Macro System in Python"
http://mail.python.org/pipermail/python-dev/2002-March/021369.html
http://mail.python.org/pipermail/python-dev/2002-March/021467.html
i've had an idea:

why not extending the def statement?

class bar(object):
    def foo(class,arg1) is classmethod:
        pass
    def bar(arg1) is staticmethod:
	pass
    
def X(...) is Y:   #don't know if 'is' is realy a goog idea...
  <<block>>

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()"
		try:
                    return fun(*arguments,**keywords)
		finally:
			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"):
	pass

what do you think? 

arne




More information about the Python-list mailing list