Thursday, May 25, 2006

DeferArgs 0.3 by Example

DeferArgs 0.3, just a few hours after 0.2, is now released here. The only update is support for attemp/catch-all blocks without any @catch(type) handlers. In response to some people in, here are examples that show what can be done more clearly.

To write any function that can accept deferred arguments nicely:

def printArgs(*args, **kwargs):
print args
print kwargs

To add psuedo-exception handlers and a psuedo-finally block to a @deferargs decorated function:

def printArgs(*args, **kwargs):
print args
print kwargs
print "This one is important! ", kwargs['important']
def onKeyError(e):
print "There was no important kwarg!"
def onAnyError(e):
print "Crap!"
def _(r):
print "Every thing is done."

There is also a model for a psuedo-try block, which basically decorates just calls the function immediately when you define it and its catch/cleanup handlers:

def this():
assert False
def _(r)
print "And thats it."

No comments:

I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive