Patchwork [V6] py3: make keys of keyword arguments strings

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 13, 2016, 3:25 p.m.
Message ID <3728b3d6924f6d4c92a9.1481642727@pulkit-goyal>
Download mbox | patch
Permalink /patch/17892/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 13, 2016, 3:25 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1481642620 -19800
#      Tue Dec 13 20:53:40 2016 +0530
# Node ID 3728b3d6924f6d4c92a9f7673a792805e8ba3c4b
# Parent  95b076f5ddee5ab7bd208b8c2f42121ce9907129
py3: make keys of keyword arguments strings

keys of keyword arguments on Python 3 has to be string. We are dealing with
bytes in our codebase so the keys are also bytes. Done that using
pycompat.strkwargs().

Also after this patch, `hg version` now runs on Python 3.5. Hurray!
Yuya Nishihara - Dec. 14, 2016, 1:17 p.m.
On Tue, 13 Dec 2016 20:55:27 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1481642620 -19800
> #      Tue Dec 13 20:53:40 2016 +0530
> # Node ID 3728b3d6924f6d4c92a9f7673a792805e8ba3c4b
> # Parent  95b076f5ddee5ab7bd208b8c2f42121ce9907129
> py3: make keys of keyword arguments strings

Queued this, thanks.
Pulkit Goyal - Dec. 21, 2016, 10:09 p.m.
> Also after this patch, `hg version` now runs on Python 3.5. Hurray!

I just realised that this may not run for other people who have set up
some aliases in hgrc or have a different hgrc than me. So still we are
not able to run `hg version` on Python 3, but we will soon.
>
> diff -r 95b076f5ddee -r 3728b3d6924f mercurial/dispatch.py
> --- a/mercurial/dispatch.py     Mon Nov 28 05:45:22 2016 +0000
> +++ b/mercurial/dispatch.py     Tue Dec 13 20:53:40 2016 +0530
> @@ -803,7 +803,8 @@
>
>          msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
>          ui.log("command", '%s\n', msg)
> -        d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
> +        strcmdopt = pycompat.strkwargs(cmdoptions)
> +        d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
>          try:
>              return runcommand(lui, repo, cmd, fullargs, ui, options, d,
>                                cmdpats, cmdoptions)
> diff -r 95b076f5ddee -r 3728b3d6924f tests/test-check-py3-commands.t
> --- a/tests/test-check-py3-commands.t   Mon Nov 28 05:45:22 2016 +0000
> +++ b/tests/test-check-py3-commands.t   Tue Dec 13 20:53:40 2016 +0530
> @@ -9,6 +9,6 @@
>    >   $PYTHON3 `which hg` $cmd 2>&1 2>&1 | tail -1
>    > done
>    version
> -  TypeError: Can't convert 'bytes' object to str implicitly
> +  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>    debuginstall
>    TypeError: Can't convert 'bytes' object to str implicitly

Patch

diff -r 95b076f5ddee -r 3728b3d6924f mercurial/dispatch.py
--- a/mercurial/dispatch.py	Mon Nov 28 05:45:22 2016 +0000
+++ b/mercurial/dispatch.py	Tue Dec 13 20:53:40 2016 +0530
@@ -803,7 +803,8 @@ 
 
         msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
         ui.log("command", '%s\n', msg)
-        d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
+        strcmdopt = pycompat.strkwargs(cmdoptions)
+        d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
         try:
             return runcommand(lui, repo, cmd, fullargs, ui, options, d,
                               cmdpats, cmdoptions)
diff -r 95b076f5ddee -r 3728b3d6924f tests/test-check-py3-commands.t
--- a/tests/test-check-py3-commands.t	Mon Nov 28 05:45:22 2016 +0000
+++ b/tests/test-check-py3-commands.t	Tue Dec 13 20:53:40 2016 +0530
@@ -9,6 +9,6 @@ 
   >   $PYTHON3 `which hg` $cmd 2>&1 2>&1 | tail -1
   > done
   version
-  TypeError: Can't convert 'bytes' object to str implicitly
+  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   debuginstall
   TypeError: Can't convert 'bytes' object to str implicitly