[PATCH 3 of 3 V2] py3: make keys of keyword arguments strings

Pulkit Goyal 7895pulkit at gmail.com
Wed Dec 7 13:36:41 EST 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1481085372 -19800
#      Wed Dec 07 10:06:12 2016 +0530
# Node ID 6d77c3065d5666a5619cd359bca3e931351d3e62
# Parent  85d610c83bda09dea2393c22e415dd9656f5a7f2
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. We need to convert the keys
to unicodes to make the code run. We have to also reverse this process so that
functions on args dictionary like get() etc. don't result in key not found.

Also after this patch, `hg version` now runs on Python 3.5. Hurray!

diff -r 85d610c83bda -r 6d77c3065d56 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Wed Dec 07 21:53:03 2016 +0530
+++ b/mercurial/dispatch.py	Wed Dec 07 10:06:12 2016 +0530
@@ -803,6 +803,7 @@
 
         msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
         ui.log("command", '%s\n', msg)
+        cmdoptions = pycompat.strkwargs(cmdoptions)
         d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
         try:
             return runcommand(lui, repo, cmd, fullargs, ui, options, d,
diff -r 85d610c83bda -r 6d77c3065d56 tests/test-check-py3-commands.t
--- a/tests/test-check-py3-commands.t	Wed Dec 07 21:53:03 2016 +0530
+++ b/tests/test-check-py3-commands.t	Wed Dec 07 10:06:12 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


More information about the Mercurial-devel mailing list