Add a test for the UnboundLocal error seen here and remove the
no-longer-needed initialization. I'm not 100% sure we want to do both
(due to the risk of callback-doubling), but the old way where the caller
saw one error and the future resolved to a different error was clearly
incorrect, and leaving the future unresolved doesn't seem right either.
return True
exc_info = None
with ExceptionStackContext(handle_error):
- result = None
try:
result = f(*args, **kwargs)
except:
exc_info = sys.exc_info()
+ raise
assert result is None, ("@return_future should not be used with "
"functions that return values")
if exc_info is not None:
def test_immediate_failure(self):
with self.assertRaises(ZeroDivisionError):
+ # The caller sees the error just like a normal function.
self.immediate_failure(callback=self.stop)
+ # The callback is also run, with a future that contains the error.
+ future = self.wait()
+ with self.assertRaises(ZeroDivisionError):
+ future.result()
def test_callback_kw(self):
future = self.sync_future(callback=self.stop)