changeset 48934:06de08b36c82

py3: use str instead of pycompat.unicode pycompat.unicode is an alias to str. Differential Revision: https://phab.mercurial-scm.org/D12340
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 21 Feb 2022 11:24:57 -0700
parents 78f1de3f4be7
children 2cce2fa5bcf7
files hgext/convert/common.py hgext/convert/convcmd.py hgext/convert/darcs.py hgext/lfs/blobstore.py hgext/phabricator.py hgext/win32mbcs.py mercurial/hgweb/__init__.py mercurial/i18n.py mercurial/scmutil.py mercurial/templatefilters.py
diffstat 10 files changed, 15 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/convert/common.py	Mon Feb 21 11:24:57 2022 -0700
@@ -246,7 +246,7 @@
         if not encoding:
             encoding = self.encoding or b'utf-8'
 
-        if isinstance(s, pycompat.unicode):
+        if isinstance(s, str):
             return s.encode("utf-8")
         try:
             return s.decode(pycompat.sysstr(encoding)).encode("utf-8")
--- a/hgext/convert/convcmd.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/convert/convcmd.py	Mon Feb 21 11:24:57 2022 -0700
@@ -86,7 +86,7 @@
 
 
 def recode(s):
-    if isinstance(s, pycompat.unicode):
+    if isinstance(s, str):
         return s.encode(pycompat.sysstr(orig_encoding), 'replace')
     else:
         return s.decode('utf-8').encode(
--- a/hgext/convert/darcs.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/convert/darcs.py	Mon Feb 21 11:24:57 2022 -0700
@@ -113,7 +113,7 @@
         shutil.rmtree(self.tmppath, ignore_errors=True)
 
     def recode(self, s, encoding=None):
-        if isinstance(s, pycompat.unicode):
+        if isinstance(s, str):
             # XMLParser returns unicode objects for anything it can't
             # encode into ASCII. We convert them back to str to get
             # recode's normal conversion behavior.
--- a/hgext/lfs/blobstore.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/lfs/blobstore.py	Mon Feb 21 11:24:57 2022 -0700
@@ -273,7 +273,7 @@
         except (AttributeError, IndexError):
             # it might be anything, for example a string
             reason = inst.reason
-        if isinstance(reason, pycompat.unicode):
+        if isinstance(reason, str):
             # SSLError of Python 2.7.9 contains a unicode
             reason = encoding.unitolocal(reason)
         return reason
@@ -406,7 +406,7 @@
             )
 
         def encodestr(x):
-            if isinstance(x, pycompat.unicode):
+            if isinstance(x, str):
                 return x.encode('utf-8')
             return x
 
--- a/hgext/phabricator.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/phabricator.py	Mon Feb 21 11:24:57 2022 -0700
@@ -219,9 +219,7 @@
         rawparams = encoding.unifromlocal(wdirvfs.read(b".arcconfig"))
         # json.loads only returns unicode strings
         arcconfig = pycompat.rapply(
-            lambda x: encoding.unitolocal(x)
-            if isinstance(x, pycompat.unicode)
-            else x,
+            lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
             pycompat.json_loads(rawparams),
         )
 
@@ -447,9 +445,7 @@
                 time.sleep(retry_interval)
     ui.debug(b'Conduit Response: %s\n' % body)
     parsed = pycompat.rapply(
-        lambda x: encoding.unitolocal(x)
-        if isinstance(x, pycompat.unicode)
-        else x,
+        lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
         # json.loads only accepts bytes from py3.6+
         pycompat.json_loads(encoding.unifromlocal(body)),
     )
@@ -473,9 +469,7 @@
     rawparams = encoding.unifromlocal(ui.fin.read())
     # json.loads only returns unicode strings
     params = pycompat.rapply(
-        lambda x: encoding.unitolocal(x)
-        if isinstance(x, pycompat.unicode)
-        else x,
+        lambda x: encoding.unitolocal(x) if isinstance(x, str) else x,
         pycompat.json_loads(rawparams),
     )
     # json.dumps only accepts unicode strings
--- a/hgext/win32mbcs.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/hgext/win32mbcs.py	Mon Feb 21 11:24:57 2022 -0700
@@ -94,7 +94,7 @@
 
 
 def encode(arg):
-    if isinstance(arg, pycompat.unicode):
+    if isinstance(arg, str):
         return arg.encode(_encoding)
     elif isinstance(arg, tuple):
         return tuple(map(encode, arg))
@@ -135,7 +135,7 @@
 
 
 def wrapper(func, args, kwds):
-    return basewrapper(func, pycompat.unicode, encode, decode, args, kwds)
+    return basewrapper(func, str, encode, decode, args, kwds)
 
 
 def reversewrapper(func, args, kwds):
--- a/mercurial/hgweb/__init__.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/mercurial/hgweb/__init__.py	Mon Feb 21 11:24:57 2022 -0700
@@ -36,7 +36,7 @@
     - list of virtual:real tuples (multi-repo view)
     """
 
-    if isinstance(config, pycompat.unicode):
+    if isinstance(config, str):
         raise error.ProgrammingError(
             b'Mercurial only supports encoded strings: %r' % config
         )
--- a/mercurial/i18n.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/mercurial/i18n.py	Mon Feb 21 11:24:57 2022 -0700
@@ -85,9 +85,9 @@
 
     cache = _msgcache.setdefault(encoding.encoding, {})
     if message not in cache:
-        if type(message) is pycompat.unicode:
+        if type(message) is str:
             # goofy unicode docstrings in test
-            paragraphs = message.split(u'\n\n')  # type: List[pycompat.unicode]
+            paragraphs = message.split(u'\n\n')  # type: List[str]
         else:
             # should be ascii, but we have unicode docstrings in test, which
             # are converted to utf-8 bytes on Python 3.
--- a/mercurial/scmutil.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/mercurial/scmutil.py	Mon Feb 21 11:24:57 2022 -0700
@@ -227,7 +227,7 @@
         except (AttributeError, IndexError):
             # it might be anything, for example a string
             reason = inst.reason
-        if isinstance(reason, pycompat.unicode):
+        if isinstance(reason, str):
             # SSLError of Python 2.7.9 contains a unicode
             reason = encoding.unitolocal(reason)
         ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason))
--- a/mercurial/templatefilters.py	Tue Mar 08 10:58:22 2022 +0100
+++ b/mercurial/templatefilters.py	Mon Feb 21 11:24:57 2022 -0700
@@ -372,9 +372,7 @@
     """Any text. Returns the input text rendered as a sequence of
     XML entities.
     """
-    text = pycompat.unicode(
-        text, pycompat.sysstr(encoding.encoding), r'replace'
-    )
+    text = str(text, pycompat.sysstr(encoding.encoding), r'replace')
     return b''.join([b'&#%d;' % ord(c) for c in text])