From: Ben Darnell Date: Fri, 27 Apr 2018 14:52:41 +0000 (-0400) Subject: stack_context: Deprecate StackContext class X-Git-Tag: v5.1.0b1~21^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1fdc30ecd83f6f1af1faad94f765d3d8616f44e;p=thirdparty%2Ftornado.git stack_context: Deprecate StackContext class --- diff --git a/tornado/stack_context.py b/tornado/stack_context.py index 2f26f3845..6b2747356 100644 --- a/tornado/stack_context.py +++ b/tornado/stack_context.py @@ -64,12 +64,18 @@ Here are a few rules of thumb for when it's necessary: persist across asynchronous calls, create a new `StackContext` (or `ExceptionStackContext`), and make your asynchronous calls in a ``with`` block that references your `StackContext`. + +.. deprecated:: 5.1 + + The ``stack_context`` package is deprecated and will be removed in + Tornado 6.0. """ from __future__ import absolute_import, division, print_function import sys import threading +import warnings from tornado.util import raise_exc_info @@ -107,6 +113,8 @@ class StackContext(object): and not necessary in most applications. """ def __init__(self, context_factory): + warnings.warn("StackContext is deprecated and will be removed in Tornado 6.0", + DeprecationWarning) self.context_factory = context_factory self.contexts = [] self.active = True diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index b1b22b1af..81b655171 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -25,7 +25,8 @@ from tornado.log import app_log from tornado.platform.select import _Select from tornado.stack_context import ExceptionStackContext, StackContext, wrap, NullContext from tornado.testing import AsyncTestCase, bind_unused_port, ExpectLog, gen_test -from tornado.test.util import unittest, skipIfNonUnix, skipOnTravis, skipBefore35, exec_test +from tornado.test.util import (unittest, skipIfNonUnix, skipOnTravis, + skipBefore35, exec_test, ignore_deprecation) try: from concurrent import futures @@ -535,11 +536,12 @@ class TestIOLoopAddCallback(AsyncTestCase): self.assertNotIn('c2', self.active_contexts) self.stop() - with StackContext(functools.partial(self.context, 'c1')): - wrapped = wrap(f1) + with ignore_deprecation(): + with StackContext(functools.partial(self.context, 'c1')): + wrapped = wrap(f1) - with StackContext(functools.partial(self.context, 'c2')): - self.add_callback(wrapped) + with StackContext(functools.partial(self.context, 'c2')): + self.add_callback(wrapped) self.wait() @@ -553,11 +555,12 @@ class TestIOLoopAddCallback(AsyncTestCase): self.assertNotIn('c2', self.active_contexts) self.stop((foo, bar)) - with StackContext(functools.partial(self.context, 'c1')): - wrapped = wrap(f1) + with ignore_deprecation(): + with StackContext(functools.partial(self.context, 'c1')): + wrapped = wrap(f1) - with StackContext(functools.partial(self.context, 'c2')): - self.add_callback(wrapped, 1, bar=2) + with StackContext(functools.partial(self.context, 'c2')): + self.add_callback(wrapped, 1, bar=2) result = self.wait() self.assertEqual(result, (1, 2))