From: Ben Darnell Date: Mon, 4 Mar 2013 00:29:39 +0000 (-0500) Subject: Allow the callback in @return_future to be run with no arguments. X-Git-Tag: v3.0.0~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94a5a4027210d082115f96308fd5527cb82b6e33;p=thirdparty%2Ftornado.git Allow the callback in @return_future to be run with no arguments. --- diff --git a/tornado/concurrent.py b/tornado/concurrent.py index c92bda0b2..2b2d06a38 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -153,8 +153,9 @@ def return_future(f): @functools.wraps(f) def wrapper(*args, **kwargs): future = Future() - callback, args, kwargs = replacer.replace(future.set_result, - args, kwargs) + callback, args, kwargs = replacer.replace( + lambda value=None: future.set_result(value), + args, kwargs) def handle_error(typ, value, tb): future.set_exception(value) diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index 8e758404c..4e5380e84 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -52,6 +52,10 @@ class ReturnFutureTest(AsyncTestCase): # implementations the last event prior to callback resolution wins. return 42 + @return_future + def no_result_future(self, callback): + callback() + def test_immediate_failure(self): with self.assertRaises(ZeroDivisionError): # The caller sees the error just like a normal function. @@ -126,6 +130,11 @@ class ReturnFutureTest(AsyncTestCase): # when we wait. self.assertRaises(ZeroDivisionError, self.wait) + def test_no_result_future(self): + self.no_result_future(self.stop) + result = self.wait() + self.assertIs(result, None) + # The following series of classes demonstrate and test various styles # of use, with and without generators and futures. class CapServer(TCPServer):