Patchwork [4,of,9] py3: convert kwargs' keys' to str using pycompat.strkwargs()

login
register
mail settings
Submitter Pulkit Goyal
Date June 23, 2017, 7:54 p.m.
Message ID <4e2f4798c3785ff71626.1498247698@workspace>
Download mbox | patch
Permalink /patch/21647/
State Accepted
Headers show

Comments

Pulkit Goyal - June 23, 2017, 7:54 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1498081576 -19800
#      Thu Jun 22 03:16:16 2017 +0530
# Node ID 4e2f4798c3785ff716264679aa34122cc158bd02
# Parent  4fc224b346e387d4f79ad368049bef13e5bde981
py3: convert kwargs' keys' to str using pycompat.strkwargs()

On Python 3, we must have keys of keyword arguments as str.
Yuya Nishihara - June 24, 2017, 3:50 a.m.
On Sat, 24 Jun 2017 01:24:58 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1498081576 -19800
> #      Thu Jun 22 03:16:16 2017 +0530
> # Node ID 4e2f4798c3785ff716264679aa34122cc158bd02
> # Parent  4fc224b346e387d4f79ad368049bef13e5bde981
> py3: convert kwargs' keys' to str using pycompat.strkwargs()

> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
> --- a/mercurial/filemerge.py
> +++ b/mercurial/filemerge.py
> @@ -534,7 +534,7 @@
>      props['templ'] = template
>      props['ctx'] = ctx
>      props['repo'] = repo
> -    templateresult = template.render(props)
> +    templateresult = template.render(pycompat.strkwargs(props))

This isn't kwargs. Dropped only this part.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1610,7 +1610,7 @@ 
     for name in getbundle2partsorder:
         func = getbundle2partsmapping[name]
         func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
-             **kwargs)
+             **pycompat.strkwargs(kwargs))
 
     return bundler.getchunks()
 
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -534,7 +534,7 @@ 
     props['templ'] = template
     props['ctx'] = ctx
     props['repo'] = repo
-    templateresult = template.render(props)
+    templateresult = template.render(pycompat.strkwargs(props))
 
     label = ('%s:' % label).ljust(pad + 1)
     mark = '%s %s' % (label, templateresult)
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -24,6 +24,7 @@ 
 from . import (
     error,
     mdiff,
+    pycompat,
     util,
     vfs as vfsmod,
 )
@@ -455,7 +456,8 @@ 
         extrakwargs['base_marker'] = '|||||||'
         extrakwargs['name_base'] = name_base
         extrakwargs['minimize'] = False
-    for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs):
+    for line in m3.merge_lines(name_a=name_a, name_b=name_b,
+                                    **pycompat.strkwargs(extrakwargs)):
         out.write(line)
 
     if not opts.get('print'):
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -119,23 +119,24 @@ 
     expand 'end_foos'.
     '''
     templ = mapping['templ']
+    strmapping = pycompat.strkwargs(mapping)
     if not plural:
         plural = name + 's'
     if not values:
         noname = 'no_' + plural
         if noname in templ:
-            yield templ(noname, **mapping)
+            yield templ(noname, **strmapping)
         return
     if name not in templ:
         if isinstance(values[0], bytes):
             yield separator.join(values)
         else:
             for v in values:
-                yield dict(v, **mapping)
+                yield dict(v, **strmapping)
         return
     startname = 'start_' + plural
     if startname in templ:
-        yield templ(startname, **mapping)
+        yield templ(startname, **strmapping)
     vmapping = mapping.copy()
     def one(v, tag=name):
         try:
@@ -146,7 +147,7 @@ 
                     vmapping[a] = b
             except ValueError:
                 vmapping[name] = v
-        return templ(tag, **vmapping)
+        return templ(tag, **pycompat.strkwargs(vmapping))
     lastname = 'last_' + name
     if lastname in templ:
         last = values.pop()
@@ -158,7 +159,7 @@ 
         yield one(last, tag=lastname)
     endname = 'end_' + plural
     if endname in templ:
-        yield templ(endname, **mapping)
+        yield templ(endname, **strmapping)
 
 def _formatrevnode(ctx):
     """Format changeset as '{rev}:{node|formatnode}', which is the default
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -371,7 +371,7 @@ 
         except TemplateNotFound:
             v = default
     if callable(v):
-        return v(**mapping)
+        return v(**pycompat.strkwargs(mapping))
     return v
 
 def buildtemplate(exp, context):