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

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 21, 2016, 4:23 p.m.
Message ID <a2f55e5d78ca779bd031.1482337397@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/17991/
State Accepted
Headers show

Comments

Pierre-Yves David - Dec. 21, 2016, 4:23 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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'))