Python 3.9 is now generally available.

google.appengine.ext.ndb.Return

Return from a tasklet in Python 2.

Inherits From: expected_type

In Python 2, generators may not return a value. In order to return a value from a tasklet, then, it is necessary to raise an instance of this exception with the return value:

@ndb.tasklet
def get_some_stuff():
  future1 = get_something_async()
  future2 = get_something_else_async()
  thing1, thing2 = yield future1, future2
  result = compute_result(thing1, thing2)
  raise ndb.Return(result)

In Python 3, you can simply return the result:

@ndb.tasklet
def get_some_stuff():
  future1 = get_something_async()
  future2 = get_something_else_async()
  thing1, thing2 = yield future1, future2
  result = compute_result(thing1, thing2)
  return result