]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
When @return_future's callback is run with no args, don't pass an arg to client callback.
authorBen Darnell <ben@bendarnell.com>
Mon, 4 Mar 2013 01:14:22 +0000 (20:14 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 4 Mar 2013 01:14:22 +0000 (20:14 -0500)
tornado/concurrent.py
tornado/test/concurrent_test.py

index 2b2d06a3880cc9ea91c527c0cbc10178d2fe6a9a..dd0d015f967dae139388535452161322a825a650 100644 (file)
@@ -116,6 +116,8 @@ def run_on_executor(fn):
     return wrapper
 
 
+_NO_RESULT = object()
+
 def return_future(f):
     """Decorator to make a function that returns via callback return a `Future`.
 
@@ -154,7 +156,7 @@ def return_future(f):
     def wrapper(*args, **kwargs):
         future = Future()
         callback, args, kwargs = replacer.replace(
-            lambda value=None: future.set_result(value),
+            lambda value=_NO_RESULT: future.set_result(value),
             args, kwargs)
 
         def handle_error(typ, value, tb):
@@ -185,7 +187,11 @@ def return_future(f):
         # the callback triggers its exception by calling future.result()).
         if callback is not None:
             def run_callback(future):
-                callback(future.result())
+                result = future.result()
+                if result is _NO_RESULT:
+                    callback()
+                else:
+                    callback(future.result())
             future.add_done_callback(wrap(run_callback))
         return future
     return wrapper
index 4e5380e846027bab57be67210089f835e062ccf1..7291428d621573a099dbf0d0e9b2ee6fafc7e489 100644 (file)
@@ -131,9 +131,17 @@ class ReturnFutureTest(AsyncTestCase):
         self.assertRaises(ZeroDivisionError, self.wait)
 
     def test_no_result_future(self):
-        self.no_result_future(self.stop)
+        future = self.no_result_future(self.stop)
         result = self.wait()
         self.assertIs(result, None)
+        # result of this future is undefined, but not an error
+        future.result()
+
+    def test_no_result_future_callback(self):
+        future = self.no_result_future(callback=lambda: self.stop())
+        result = self.wait()
+        self.assertIs(result, None)
+        future.result()
 
 # The following series of classes demonstrate and test various styles
 # of use, with and without generators and futures.