D4743: encoding: remove unnecessary lambdas from _encodingfixers

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed Sep 26 00:03:18 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  They have been unnecessary since https://phab.mercurial-scm.org/rHG1a3a08b5d4d572c9f7ef9a3e9592ff4b15014abf (encoding: remove
  workaround for locale.getpreferredencoding(), 2017-05-13). Also rename
  the variable since "fixer" sounds like a function.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4743

AFFECTED FILES
  mercurial/encoding.py

CHANGE DETAILS

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -68,21 +68,21 @@
     environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8'))
                    for k, v in os.environ.items())  # re-exports
 
-_encodingfixers = {
-    '646': lambda: 'ascii',
-    'ANSI_X3.4-1968': lambda: 'ascii',
+_encodingrewrites = {
+    '646': 'ascii',
+    'ANSI_X3.4-1968': 'ascii',
 }
 # cp65001 is a Windows variant of utf-8, which isn't supported on Python 2.
 # No idea if it should be rewritten to the canonical name 'utf-8' on Python 3.
 # https://bugs.python.org/issue13216
 if pycompat.iswindows and not pycompat.ispy3:
-    _encodingfixers['cp65001'] = lambda: 'utf-8'
+    _encodingrewrites['cp65001'] = 'utf-8'
 
 try:
     encoding = environ.get("HGENCODING")
     if not encoding:
         encoding = locale.getpreferredencoding().encode('ascii') or 'ascii'
-        encoding = _encodingfixers.get(encoding, lambda: encoding)()
+        encoding = _encodingrewrites.get(encoding, encoding)
 except locale.Error:
     encoding = 'ascii'
 encodingmode = environ.get("HGENCODINGMODE", "strict")



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list