Patchwork [6,of,6] py3: use pycompat.bytestr() in place of str()

login
register
mail settings
Submitter Pulkit Goyal
Date June 20, 2017, 11:31 p.m.
Message ID <48ffac16c59bf9e2b2c5.1498001492@workspace>
Download mbox | patch
Permalink /patch/21553/
State Accepted
Headers show

Comments

Pulkit Goyal - June 20, 2017, 11:31 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497991834 -19800
#      Wed Jun 21 02:20:34 2017 +0530
# Node ID 48ffac16c59bf9e2b2c5acab728eb398b25249eb
# Parent  41cfbb320dd387e96fdf44b114cbaa8053a892cb
py3: use pycompat.bytestr() in place of str()
Yuya Nishihara - June 21, 2017, 2:59 p.m.
On Wed, 21 Jun 2017 05:01:32 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1497991834 -19800
> #      Wed Jun 21 02:20:34 2017 +0530
> # Node ID 48ffac16c59bf9e2b2c5acab728eb398b25249eb
> # Parent  41cfbb320dd387e96fdf44b114cbaa8053a892cb
> py3: use pycompat.bytestr() in place of str()

Queued, thanks.

> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -622,7 +622,8 @@
>      repo = args['repo']
>      ctx = args['ctx']
>      pctxs = scmutil.meaningfulparents(repo, ctx)
> -    prevs = [str(p.rev()) for p in pctxs]  # ifcontains() needs a list of str
> +    # ifcontains() needs a list of str
> +    prevs = [pycompat.bytestr(p.rev()) for p in pctxs]
>      parents = [[('rev', p.rev()),
>                  ('node', p.hex()),
>                  ('phase', p.phasestr())]
> @@ -651,7 +652,8 @@
>      be evaluated"""
>      args = pycompat.byteskwargs(args)
>      repo = args['ctx'].repo()
> -    revs = [str(r) for r in revs]  # ifcontains() needs a list of str
> +    # ifcontains() needs a list of str
> +    revs = [pycompat.bytestr(r) for r in revs]

These two could be '%d' % r. Can you send a follow up?

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -622,7 +622,8 @@ 
     repo = args['repo']
     ctx = args['ctx']
     pctxs = scmutil.meaningfulparents(repo, ctx)
-    prevs = [str(p.rev()) for p in pctxs]  # ifcontains() needs a list of str
+    # ifcontains() needs a list of str
+    prevs = [pycompat.bytestr(p.rev()) for p in pctxs]
     parents = [[('rev', p.rev()),
                 ('node', p.hex()),
                 ('phase', p.phasestr())]
@@ -651,7 +652,8 @@ 
     be evaluated"""
     args = pycompat.byteskwargs(args)
     repo = args['ctx'].repo()
-    revs = [str(r) for r in revs]  # ifcontains() needs a list of str
+    # ifcontains() needs a list of str
+    revs = [pycompat.bytestr(r) for r in revs]
     f = _showlist(name, revs, args)
     return _hybrid(f, revs,
                    lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1106,7 +1106,7 @@ 
     elif thing is None:
         pass
     elif not util.safehasattr(thing, '__iter__'):
-        yield str(thing)
+        yield pycompat.bytestr(thing)
     else:
         for i in thing:
             i = templatekw.unwraphybrid(i)
@@ -1115,7 +1115,7 @@ 
             elif i is None:
                 pass
             elif not util.safehasattr(i, '__iter__'):
-                yield str(i)
+                yield pycompat.bytestr(i)
             else:
                 for j in _flatten(i):
                     yield j