Patchwork [1,of,4] color: drop use of the 'global' keyword for _terminfo_params

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 21, 2016, 4:23 p.m.
Message ID <0038b17608085d0bc611.1482337396@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/17988/
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 1479490033 -3600
#      Fri Nov 18 18:27:13 2016 +0100
# Node ID 0038b17608085d0bc611dc7b0c9d1b97a1ea05e4
# Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
# EXP-Topic color
color: drop use of the 'global' keyword for _terminfo_params

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 '_terminfo_params.clear()' and
drop the global.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -197,7 +197,6 @@  testedwith = 'ships-with-hg-core'
 def _terminfosetup(ui, mode):
     '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
 
-    global _terminfo_params
     # If we failed to load curses, we go ahead and return.
     if not _terminfo_params:
         return
@@ -215,7 +214,7 @@  def _terminfosetup(ui, mode):
     try:
         curses.setupterm()
     except curses.error as e:
-        _terminfo_params = {}
+        _terminfo_params.clear()
         return
 
     for key, (b, e, c) in _terminfo_params.items():
@@ -232,11 +231,9 @@  def _terminfosetup(ui, mode):
         if mode == "terminfo":
             ui.warn(_("no terminfo entry for setab/setaf: reverting to "
               "ECMA-48 color\n"))
-        _terminfo_params = {}
+        _terminfo_params.clear()
 
 def _modesetup(ui, coloropt):
-    global _terminfo_params
-
     if coloropt == 'debug':
         return 'debug'
 
@@ -280,13 +277,13 @@  def _modesetup(ui, coloropt):
             ui.warn(_('warning: failed to set color mode to %s\n') % mode)
 
     if realmode == 'win32':
-        _terminfo_params = {}
+        _terminfo_params.clear()
         if not w32effects:
             modewarn()
             return None
         _effects.update(w32effects)
     elif realmode == 'ansi':
-        _terminfo_params = {}
+        _terminfo_params.clear()
     elif realmode == 'terminfo':
         _terminfosetup(ui, mode)
         if not _terminfo_params: