]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove obsolete util.compat.nested
authorGord Thompson <gord@gordthompson.com>
Sun, 1 Mar 2020 18:30:56 +0000 (11:30 -0700)
committerGord Thompson <gord@gordthompson.com>
Mon, 2 Mar 2020 17:37:20 +0000 (10:37 -0700)
Fixes: #5177
Change-Id: Ie02b0c065e3833f43e056ad9c31f414871d9e8ee

lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/compat.py
test/engine/test_execute.py

index b0ceb802a453dfd8957ff07a38cd8efdf761f8fe..b4610a1b082d6c5bef45dc54ceaeb27ede465cd8 100644 (file)
@@ -58,7 +58,6 @@ from .compat import iterbytes  # noqa
 from .compat import itertools_filter  # noqa
 from .compat import itertools_filterfalse  # noqa
 from .compat import namedtuple  # noqa
-from .compat import nested  # noqa
 from .compat import next  # noqa
 from .compat import parse_qsl  # noqa
 from .compat import pickle  # noqa
index 8967955cd7b5e471508c831cb61b06b8186608ef..104e8e03dd6cdf282f85e75372ef988e2cb65ea6 100644 (file)
@@ -369,41 +369,6 @@ else:
     import collections as collections_abc  # noqa
 
 
-@contextlib.contextmanager
-def nested(*managers):
-    """Implement contextlib.nested, mostly for unit tests.
-
-    As tests still need to run on py2.6 we can't use multiple-with yet.
-
-    Function is removed in py3k but also emits deprecation warning in 2.7
-    so just roll it here for everyone.
-
-    """
-
-    exits = []
-    vars_ = []
-    exc = (None, None, None)
-    try:
-        for mgr in managers:
-            exit_ = mgr.__exit__
-            enter = mgr.__enter__
-            vars_.append(enter())
-            exits.append(exit_)
-        yield vars_
-    except:
-        exc = sys.exc_info()
-    finally:
-        while exits:
-            exit_ = exits.pop()  # noqa
-            try:
-                if exit_(*exc):
-                    exc = (None, None, None)
-            except:
-                exc = sys.exc_info()
-        if exc != (None, None, None):
-            reraise(exc[0], exc[1], exc[2])
-
-
 def raise_from_cause(exception, exc_info=None):
     if exc_info is None:
         exc_info = sys.exc_info()
index 5acd14177e1d76ead2ff83efa04a30dffe4ad186..bad6c160310e7fa977e2305f672d27a408be716a 100644 (file)
@@ -47,7 +47,6 @@ from sqlalchemy.testing.schema import Column
 from sqlalchemy.testing.schema import Table
 from sqlalchemy.testing.util import gc_collect
 from sqlalchemy.testing.util import picklers
-from sqlalchemy.util import nested
 
 
 users, metadata, users_autoinc = None, None, None
@@ -348,16 +347,14 @@ class ExecuteTest(fixtures.TestBase):
         class NonStandardException(OperationalError):
             pass
 
-        with nested(
-            patch.object(testing.db.dialect, "dbapi", Mock(Error=DBAPIError)),
-            patch.object(
-                testing.db.dialect, "is_disconnect", lambda *arg: False
-            ),
-            patch.object(
-                testing.db.dialect,
-                "do_execute",
-                Mock(side_effect=NonStandardException),
-            ),
+        with patch.object(
+            testing.db.dialect, "dbapi", Mock(Error=DBAPIError)
+        ), patch.object(
+            testing.db.dialect, "is_disconnect", lambda *arg: False
+        ), patch.object(
+            testing.db.dialect,
+            "do_execute",
+            Mock(side_effect=NonStandardException),
         ):
             with testing.db.connect() as conn:
                 assert_raises(