Stephen Thorne ([info]jerub) wrote,
@ 2005-09-06 09:33:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
funky 2.5 defgen
This is the new syntax for using the new 2.5 generators with twisted.
@defgen
def foo():
  value = yield someDeferredAction()
  row = yield someDatabaseQuery(value+1)
  yield row['column']

which is an analog of the 'old' way of doing things, like this:
def foo():
  def _increment(value):
    return value+1
  def _getcolumn(row):
    return row['column']
  return someDeferredAction(
  ).addCallback(_increment
  ).addCallback(someDatabaseQuery
  ).addCallback(_getcolumn)

Yay to christopher armstrong for putting this together, yay to PJE for writing the code for python2.5



(1 comment) - (Post a new comment)

I'm not sure...
[info]ianbicking
2005-09-06 08:29 pm UTC (link)
I think "_increment" and "_getcolumn" add substantial documentation value to your example, rendering the second example clearly superior. Plus you define you fundamental operations up front -- adding one and getting a key -- instead of embedded them inside hard-to-understand expressions.

(Reply to this)


(1 comment) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…