[PATCH 2 of 4] color: drop use of the 'global' keyword for '_style'

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Dec 21 11:23:17 EST 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1479490159 -3600
#      Fri Nov 18 18:29:19 2016 +0100
# Node ID a2f55e5d78ca779bd031a5ab6cd32167f4a6ffdf
# Parent  0038b17608085d0bc611dc7b0c9d1b97a1ea05e4
# EXP-Topic color
color: drop use of the 'global' keyword for '_style'

Using 'global' is usually a bad sign. Here it is used so that one can empty the
content of a dict at the global scope. We '_style.clear()' and drop the global.

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -545,10 +545,9 @@ def debugcolor(ui, repo, **opts):
         return _debugdisplaycolor(ui)
 
 def _debugdisplaycolor(ui):
-    global _styles
-    oldstyle = _styles
+    oldstyle = _styles.copy()
     try:
-        _styles = {}
+        _styles.clear()
         for effect in _effects.keys():
             _styles[effect] = effect
         if _terminfo_params:
@@ -564,7 +563,8 @@ def _debugdisplaycolor(ui):
         for colorname, label in items:
             ui.write(('%s\n') % colorname, label=label)
     finally:
-        _styles = oldstyle
+        _styles.clear()
+        _styles.update(oldstyle)
 
 def _debugdisplaystyle(ui):
     ui.write(_('available style:\n'))


More information about the Mercurial-devel mailing list