py3: stop normalizing .encode()/.decode() arguments to unicode
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 06 Oct 2019 17:27:51 -0400
changeset 43091 127cc1f72e70
parent 43090 1f339b503a40
child 43092 0b75457d1133
py3: stop normalizing .encode()/.decode() arguments to unicode Now that we don't byte transform string literals, we no longer need this transform. While we're here, we also drop some superfluous u'' prefix in existing callers. Differential Revision: https://phab.mercurial-scm.org/D7011
contrib/testparseutil.py
hgext/lfs/blobstore.py
mercurial/__init__.py
mercurial/pycompat.py
--- a/contrib/testparseutil.py	Sun Oct 06 16:58:55 2019 -0400
+++ b/contrib/testparseutil.py	Sun Oct 06 17:27:51 2019 -0400
@@ -49,7 +49,7 @@
     def sysstr(s):
         if isinstance(s, builtins.str):
             return s
-        return s.decode(u'latin-1')
+        return s.decode('latin-1')
 
     def opentext(f):
         return open(f, 'r')
--- a/hgext/lfs/blobstore.py	Sun Oct 06 16:58:55 2019 -0400
+++ b/hgext/lfs/blobstore.py	Sun Oct 06 17:27:51 2019 -0400
@@ -394,7 +394,7 @@
 
         def encodestr(x):
             if isinstance(x, pycompat.unicode):
-                return x.encode(u'utf-8')
+                return x.encode('utf-8')
             return x
 
         return pycompat.rapply(encodestr, response)
--- a/mercurial/__init__.py	Sun Oct 06 16:58:55 2019 -0400
+++ b/mercurial/__init__.py	Sun Oct 06 17:27:51 2019 -0400
@@ -166,14 +166,6 @@
                     if arg1idx is not None:
                         _ensureunicode(arg1idx)
 
-                # .encode() and .decode() on str/bytes/unicode don't accept
-                # byte strings on Python 3.
-                elif fn in ('encode', 'decode') and _isop(i - 1, '.'):
-                    for argn in range(2):
-                        argidx = _findargnofcall(argn)
-                        if argidx is not None:
-                            _ensureunicode(argidx)
-
                 # It changes iteritems/values to items/values as they are not
                 # present in Python 3 world.
                 elif fn in ('iteritems', 'itervalues') and not (
@@ -190,7 +182,7 @@
     # ``replacetoken`` or any mechanism that changes semantics of module
     # loading is changed. Otherwise cached bytecode may get loaded without
     # the new transformation mechanisms applied.
-    BYTECODEHEADER = b'HG\x00\x12'
+    BYTECODEHEADER = b'HG\x00\x13'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.
--- a/mercurial/pycompat.py	Sun Oct 06 16:58:55 2019 -0400
+++ b/mercurial/pycompat.py	Sun Oct 06 17:27:51 2019 -0400
@@ -206,7 +206,7 @@
             ) and not hasattr(  # hasattr-py3-only
                 s, u'__bytes__'
             ):
-                s = str(s).encode(u'ascii')
+                s = str(s).encode('ascii')
             return bytes.__new__(cls, s)
 
         def __getitem__(self, key):
@@ -237,7 +237,7 @@
         This never raises UnicodeEncodeError, but only ASCII characters
         can be round-trip by sysstr(sysbytes(s)).
         """
-        return s.encode(u'utf-8')
+        return s.encode('utf-8')
 
     def sysstr(s):
         """Return a keyword str to be passed to Python functions such as
@@ -249,18 +249,18 @@
         """
         if isinstance(s, builtins.str):
             return s
-        return s.decode(u'latin-1')
+        return s.decode('latin-1')
 
     def strurl(url):
         """Converts a bytes url back to str"""
         if isinstance(url, bytes):
-            return url.decode(u'ascii')
+            return url.decode('ascii')
         return url
 
     def bytesurl(url):
         """Converts a str url to bytes by encoding in ascii"""
         if isinstance(url, str):
-            return url.encode(u'ascii')
+            return url.encode('ascii')
         return url
 
     def raisewithtb(exc, tb):