streamclone: reimplement nested context manager
authorAugie Fackler <augie@google.com>
Fri, 21 Sep 2018 11:43:46 -0400
changeset 39757 97f2992c26f6
parent 39756 4a8bfec90ae6
child 39758 543f26ece6cf
streamclone: reimplement nested context manager It's gone in Python 3, and you can't *ctxs into a with statement. Sigh. Differential Revision: https://phab.mercurial-scm.org/D4690
mercurial/streamclone.py
--- a/mercurial/streamclone.py	Fri Sep 21 11:44:08 2018 -0400
+++ b/mercurial/streamclone.py	Fri Sep 21 11:43:46 2018 -0400
@@ -10,7 +10,6 @@
 import contextlib
 import os
 import struct
-import warnings
 
 from .i18n import _
 from . import (
@@ -568,12 +567,13 @@
 
 @contextlib.contextmanager
 def nested(*ctxs):
-    with warnings.catch_warnings():
-        # For some reason, Python decided 'nested' was deprecated without
-        # replacement. They officially advertised for filtering the deprecation
-        # warning for people who actually need the feature.
-        warnings.filterwarnings("ignore",category=DeprecationWarning)
-        with contextlib.nested(*ctxs):
+    this = ctxs[0]
+    rest = ctxs[1:]
+    with this:
+        if rest:
+            with nested(*rest):
+                yield
+        else:
             yield
 
 def consumev2(repo, fp, filecount, filesize):