color: drop use of the 'global' keyword for '_style'
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 18 Nov 2016 18:29:19 +0100
changeset 30651 27e48410380d
parent 30650 ae37e395a110
child 30652 1ec42bdd7874
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.
hgext/color.py
--- a/hgext/color.py	Fri Nov 18 18:27:13 2016 +0100
+++ b/hgext/color.py	Fri Nov 18 18:29:19 2016 +0100
@@ -546,10 +546,9 @@
         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:
@@ -565,7 +564,8 @@
         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'))