cleanup: prefer nested context managers to \-continuations
authorAugie Fackler <augie@google.com>
Wed, 20 Feb 2019 18:02:28 -0500
changeset 41760 1eb2fc21da12
parent 41759 aaad36b88298
child 41761 e2472b12c842
cleanup: prefer nested context managers to \-continuations I'd prefer Python accept a tuple of context managers, but alas it isn't meant to be. This will have to suffice. Differential Revision: https://phab.mercurial-scm.org/D5994
hgext/largefiles/overrides.py
hgext/narrow/narrowcommands.py
mercurial/exchange.py
--- a/hgext/largefiles/overrides.py	Wed Feb 20 19:28:51 2019 -0500
+++ b/hgext/largefiles/overrides.py	Wed Feb 20 18:02:28 2019 -0500
@@ -664,9 +664,9 @@
                                   _('destination largefile already exists'))
             copiedfiles.append((src, dest))
             orig(src, dest, *args, **kwargs)
-        with extensions.wrappedfunction(util, 'copyfile', overridecopyfile), \
-             extensions.wrappedfunction(scmutil, 'match', overridematch):
-            result += orig(ui, repo, listpats, opts, rename)
+        with extensions.wrappedfunction(util, 'copyfile', overridecopyfile):
+            with extensions.wrappedfunction(scmutil, 'match', overridematch):
+                result += orig(ui, repo, listpats, opts, rename)
 
         lfdirstate = lfutil.openlfdirstate(ui, repo)
         for (src, dest) in copiedfiles:
--- a/hgext/narrow/narrowcommands.py	Wed Feb 20 19:28:51 2019 -0500
+++ b/hgext/narrow/narrowcommands.py	Wed Feb 20 18:02:28 2019 -0500
@@ -278,9 +278,9 @@
             p1, p2 = ds.p1(), ds.p2()
             with ds.parentchange():
                 ds.setparents(node.nullid, node.nullid)
-            with wrappedextraprepare,\
-                 repo.ui.configoverride(overrides, 'widen'):
-                exchange.pull(repo, remote, heads=common)
+            with wrappedextraprepare:
+                with repo.ui.configoverride(overrides, 'widen'):
+                    exchange.pull(repo, remote, heads=common)
             with ds.parentchange():
                 ds.setparents(p1, p2)
         else:
@@ -296,11 +296,11 @@
                     'ellipses': False,
                 }).result()
 
-            with repo.transaction('widening') as tr,\
-                 repo.ui.configoverride(overrides, 'widen'):
-                tgetter = lambda: tr
-                bundle2.processbundle(repo, bundle,
-                        transactiongetter=tgetter)
+            with repo.transaction('widening') as tr:
+                with repo.ui.configoverride(overrides, 'widen'):
+                    tgetter = lambda: tr
+                    bundle2.processbundle(repo, bundle,
+                            transactiongetter=tgetter)
 
         with repo.transaction('widening'):
             repo.setnewnarrowpats()
--- a/mercurial/exchange.py	Wed Feb 20 19:28:51 2019 -0500
+++ b/mercurial/exchange.py	Wed Feb 20 18:02:28 2019 -0500
@@ -556,18 +556,18 @@
                % stringutil.forcebytestr(err))
         pushop.ui.debug(msg)
 
-    with wlock or util.nullcontextmanager(), \
-            lock or util.nullcontextmanager(), \
-            pushop.trmanager or util.nullcontextmanager():
-        pushop.repo.checkpush(pushop)
-        _checkpublish(pushop)
-        _pushdiscovery(pushop)
-        if not _forcebundle1(pushop):
-            _pushbundle2(pushop)
-        _pushchangeset(pushop)
-        _pushsyncphase(pushop)
-        _pushobsolete(pushop)
-        _pushbookmark(pushop)
+    with wlock or util.nullcontextmanager():
+        with lock or util.nullcontextmanager():
+            with pushop.trmanager or util.nullcontextmanager():
+                pushop.repo.checkpush(pushop)
+                _checkpublish(pushop)
+                _pushdiscovery(pushop)
+                if not _forcebundle1(pushop):
+                    _pushbundle2(pushop)
+                _pushchangeset(pushop)
+                _pushsyncphase(pushop)
+                _pushobsolete(pushop)
+                _pushbookmark(pushop)
 
     if repo.ui.configbool('experimental', 'remotenames'):
         logexchange.pullremotenames(repo, remote)