changeset 31774:7d2cbe11ae48

pycompat: introduce identity function as a compat stub I was sometimes too lazy to use 'str' instead of 'lambda a: a'. Let's add a named function for that purpose.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 29 Mar 2017 21:13:55 +0900
parents 5646d7bcd823
children 8181f378b073
files mercurial/encoding.py mercurial/pycompat.py
diffstat 2 files changed, 9 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/encoding.py	Sun Apr 02 02:29:51 2017 -0400
+++ b/mercurial/encoding.py	Wed Mar 29 21:13:55 2017 +0900
@@ -211,8 +211,8 @@
     strtolocal = unitolocal
     strfromlocal = unifromlocal
 else:
-    strtolocal = str
-    strfromlocal = str
+    strtolocal = pycompat.identity
+    strfromlocal = pycompat.identity
 
 if not _nativeenviron:
     # now encoding and helper functions are available, recreate the environ
--- a/mercurial/pycompat.py	Sun Apr 02 02:29:51 2017 -0400
+++ b/mercurial/pycompat.py	Wed Mar 29 21:13:55 2017 +0900
@@ -30,6 +30,9 @@
     import socketserver
     import xmlrpc.client as xmlrpclib
 
+def identity(a):
+    return a
+
 if ispy3:
     import builtins
     import functools
@@ -206,9 +209,7 @@
     bytechr = chr
     bytestr = str
     iterbytestr = iter
-
-    def sysstr(s):
-        return s
+    sysstr = identity
 
     # Partial backport from os.py in Python 3, which only accepts bytes.
     # In Python 2, our paths should only ever be bytes, a unicode path
@@ -222,17 +223,13 @@
 
     # In Python 2, fsdecode() has a very chance to receive bytes. So it's
     # better not to touch Python 2 part as it's already working fine.
-    def fsdecode(filename):
-        return filename
+    fsdecode = identity
 
     def getoptb(args, shortlist, namelist):
         return getopt.getopt(args, shortlist, namelist)
 
-    def strkwargs(dic):
-        return dic
-
-    def byteskwargs(dic):
-        return dic
+    strkwargs = identity
+    byteskwargs = identity
 
     osname = os.name
     ospathsep = os.pathsep