Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pycompat.py @ 31777: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 | 55c6788c54e2 |
children | 8181f378b073 |
line wrap: on
line diff
--- 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