From: Ben Darnell Date: Sun, 6 May 2018 02:43:08 +0000 (-0400) Subject: concurrent: Fully deprecate return_future X-Git-Tag: v5.1.0b1~19^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3c4e7dc9dd9f2855bce0d0b7f457d310b74e095;p=thirdparty%2Ftornado.git concurrent: Fully deprecate return_future It relies on ExceptionStackContext, so it should go away completely instead of just losing its callback argument. --- diff --git a/docs/releases/v5.1.0.rst b/docs/releases/v5.1.0.rst index f29ab2114..feeaec3fd 100644 --- a/docs/releases/v5.1.0.rst +++ b/docs/releases/v5.1.0.rst @@ -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` ~~~~~~~~~~~~~ diff --git a/tornado/auth.py b/tornado/auth.py index e0125bb6a..ab1a8503a 100644 --- a/tornado/auth.py +++ b/tornado/auth.py @@ -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. diff --git a/tornado/concurrent.py b/tornado/concurrent.py index 165f6337f..78b20919b 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -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) diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index be6840eda..737c13e14 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -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") diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 721d927dd..346968cfb 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -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):