# HG changeset patch # User Yuya Nishihara <y...@tcha.org> # Date 1490789635 -32400 # Wed Mar 29 21:13:55 2017 +0900 # Node ID 267ba0ee66701fa87ff1764323599c299cff3e1f # Parent d73490957d6162edf064055e40b321ee819187d2 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. diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -211,8 +211,8 @@ if pycompat.ispy3: 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 diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -30,6 +30,9 @@ else: import socketserver import xmlrpc.client as xmlrpclib +def identity(a): + return a + if ispy3: import builtins import functools @@ -206,9 +209,7 @@ else: 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 @@ else: # 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 _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel