]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
concurrent: Fully deprecate return_future 2378/head
authorBen Darnell <ben@bendarnell.com>
Sun, 6 May 2018 02:43:08 +0000 (22:43 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 6 May 2018 02:43:08 +0000 (22:43 -0400)
It relies on ExceptionStackContext, so it should go away completely
instead of just losing its callback argument.

docs/releases/v5.1.0.rst
tornado/auth.py
tornado/concurrent.py
tornado/test/concurrent_test.py
tornado/test/gen_test.py

index f29ab2114edeab0747e28241370824f2ef358096..feeaec3fdd6a99b7b6a44040137283ab90f5e4c5 100644 (file)
@@ -47,9 +47,7 @@ Deprecation notice
   with ``await``.
 - The ``callback`` argument to `.run_on_executor` is deprecated and will
   be removed in 6.0.
-- `.return_future` is deprecated. The wrapped function will no longer
-  accept ``callback`` arguments in Tornado 6.0, although the decorator
-  itself will not be removed.
+- `.return_future` is deprecated and will be removed in 6.0.
 
 `tornado.gen`
 ~~~~~~~~~~~~~
index e0125bb6a5d60143f4c1261caaa1cb5076549982..ab1a8503a3c7ce3a3c555fa0f58dd2333edf2125 100644 (file)
@@ -74,8 +74,8 @@ import time
 import uuid
 import warnings
 
-from tornado.concurrent import (Future, return_future, chain_future,
-                                future_set_exc_info,
+from tornado.concurrent import (Future, _non_deprecated_return_future,
+                                future_set_exc_info, chain_future,
                                 future_set_result_unless_cancelled)
 from tornado import gen
 from tornado import httpclient
@@ -148,7 +148,7 @@ class OpenIdMixin(object):
 
     * ``_OPENID_ENDPOINT``: the identity provider's URI.
     """
-    @return_future
+    @_non_deprecated_return_future
     def authenticate_redirect(self, callback_uri=None,
                               ax_attrs=["name", "email", "language", "username"],
                               callback=None):
@@ -343,7 +343,7 @@ class OAuthMixin(object):
     Subclasses must also override the `_oauth_get_user_future` and
     `_oauth_consumer_token` methods.
     """
-    @return_future
+    @_non_deprecated_return_future
     def authorize_redirect(self, callback_uri=None, extra_params=None,
                            http_client=None, callback=None):
         """Redirects the user to obtain OAuth authorization for this service.
@@ -524,7 +524,7 @@ class OAuthMixin(object):
         """
         raise NotImplementedError()
 
-    @return_future
+    @_non_deprecated_return_future
     def _oauth_get_user_future(self, access_token, callback):
         """Subclasses must override this to get basic information about the
         user.
@@ -617,7 +617,7 @@ class OAuth2Mixin(object):
     * ``_OAUTH_AUTHORIZE_URL``: The service's authorization url.
     * ``_OAUTH_ACCESS_TOKEN_URL``:  The service's access token url.
     """
-    @return_future
+    @_non_deprecated_return_future
     def authorize_redirect(self, redirect_uri=None, client_id=None,
                            client_secret=None, extra_params=None,
                            callback=None, scope=None, response_type="code"):
@@ -778,7 +778,7 @@ class TwitterMixin(OAuthMixin):
     _OAUTH_NO_CALLBACKS = False
     _TWITTER_BASE_URL = "https://api.twitter.com/1.1"
 
-    @return_future
+    @_non_deprecated_return_future
     def authenticate_redirect(self, callback_uri=None, callback=None):
         """Just like `~OAuthMixin.authorize_redirect`, but
         auto-redirects if authorized.
index 165f6337fec5ed7d46e5952f7f92f92768b6cd18..78b20919b90d47e9b28ba6babbb711ea6f4411ae 100644 (file)
@@ -510,9 +510,22 @@ def return_future(f):
 
     .. deprecated:: 5.1
 
-       New code should use coroutines directly instead of wrapping
-       callback-based code with this decorator.
+       This decorator will be removed in Tornado 6.0. New code should
+       use coroutines directly instead of wrapping callback-based code
+       with this decorator. Interactions with non-Tornado
+       callback-based code should be managed explicitly to avoid
+       relying on the `.ExceptionStackContext` built into this
+       decorator.
     """
+    warnings.warn("@return_future is deprecated, use coroutines instead",
+                  DeprecationWarning)
+    return _non_deprecated_return_future(f)
+
+
+def _non_deprecated_return_future(f):
+    # Allow auth.py to use this decorator without triggering
+    # deprecation warnings. This will go away once auth.py has removed
+    # its legacy interfaces in 6.0.
     replacer = ArgReplacer(f, 'callback')
 
     @functools.wraps(f)
index be6840eda8c4cec83355d35a3820291420132ad2..737c13e14add2f7c692a2b5b7b5084921075d4a6 100644 (file)
@@ -59,32 +59,33 @@ class MiscFutureTest(AsyncTestCase):
 
 
 class ReturnFutureTest(AsyncTestCase):
-    @return_future
-    def sync_future(self, callback):
-        callback(42)
+    with ignore_deprecation():
+        @return_future
+        def sync_future(self, callback):
+            callback(42)
 
-    @return_future
-    def async_future(self, callback):
-        self.io_loop.add_callback(callback, 42)
+        @return_future
+        def async_future(self, callback):
+            self.io_loop.add_callback(callback, 42)
 
-    @return_future
-    def immediate_failure(self, callback):
-        1 / 0
+        @return_future
+        def immediate_failure(self, callback):
+            1 / 0
 
-    @return_future
-    def delayed_failure(self, callback):
-        self.io_loop.add_callback(lambda: 1 / 0)
+        @return_future
+        def delayed_failure(self, callback):
+            self.io_loop.add_callback(lambda: 1 / 0)
 
-    @return_future
-    def return_value(self, callback):
-        # Note that the result of both running the callback and returning
-        # a value (or raising an exception) is unspecified; with current
-        # implementations the last event prior to callback resolution wins.
-        return 42
+        @return_future
+        def return_value(self, callback):
+            # Note that the result of both running the callback and returning
+            # a value (or raising an exception) is unspecified; with current
+            # implementations the last event prior to callback resolution wins.
+            return 42
 
-    @return_future
-    def no_result_future(self, callback):
-        callback()
+        @return_future
+        def no_result_future(self, callback):
+            callback()
 
     def test_immediate_failure(self):
         with self.assertRaises(ZeroDivisionError):
@@ -151,9 +152,10 @@ class ReturnFutureTest(AsyncTestCase):
             future.result()
 
     def test_kw_only_callback(self):
-        @return_future
-        def f(**kwargs):
-            kwargs['callback'](42)
+        with ignore_deprecation():
+            @return_future
+            def f(**kwargs):
+                kwargs['callback'](42)
         future = f()
         self.assertEqual(future.result(), 42)
 
@@ -307,14 +309,15 @@ class ManualCapClient(BaseCapClient):
 
 
 class DecoratorCapClient(BaseCapClient):
-    @return_future
-    def capitalize(self, request_data, callback):
-        logging.debug("capitalize")
-        self.request_data = request_data
-        self.stream = IOStream(socket.socket())
-        self.stream.connect(('127.0.0.1', self.port),
-                            callback=self.handle_connect)
-        self.callback = callback
+    with ignore_deprecation():
+        @return_future
+        def capitalize(self, request_data, callback):
+            logging.debug("capitalize")
+            self.request_data = request_data
+            self.stream = IOStream(socket.socket())
+            self.stream.connect(('127.0.0.1', self.port),
+                                callback=self.handle_connect)
+            self.callback = callback
 
     def handle_connect(self):
         logging.debug("handle_connect")
index 721d927dd4edf08e96e119723a943c4a5906056a..346968cfbc43beaf8347e8865718505c1ec1ce90 100644 (file)
@@ -68,9 +68,10 @@ class GenEngineTest(AsyncTestCase):
             self.io_loop.add_callback(functools.partial(
                 self.delay_callback, iterations - 1, callback, arg))
 
-    @return_future
-    def async_future(self, result, callback):
-        self.io_loop.add_callback(callback, result)
+    with ignore_deprecation():
+        @return_future
+        def async_future(self, result, callback):
+            self.io_loop.add_callback(callback, result)
 
     @gen.coroutine
     def async_exception(self, e):
@@ -678,9 +679,10 @@ class GenBasicTest(AsyncTestCase):
             yield gen.moment
         raise gen.Return(arg)
 
-    @return_future
-    def async_future(self, result, callback):
-        self.io_loop.add_callback(callback, result)
+    with ignore_deprecation():
+        @return_future
+        def async_future(self, result, callback):
+            self.io_loop.add_callback(callback, result)
 
     @gen.coroutine
     def async_exception(self, e):