Re: [PATCH] py3: make keys of keyword arguments strings
On Wed, Dec 7, 2016 at 7:44 PM, Yuya Nishihara wrote: > On Wed, 07 Dec 2016 10:43:24 +0530, Pulkit Goyal wrote: >> # HG changeset patch >> # User Pulkit Goyal <7895pul...@gmail.com> >> # Date 1481085372 -19800 >> # Wed Dec 07 10:06:12 2016 +0530 >> # Node ID 60372f5694c6b188fba456cfd269690e84ac645b >> # Parent 831d29deed083618bddc2fade7d2a6fe297c896d >> 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! > > Nice! > >> diff -r 831d29deed08 -r 60372f5694c6 mercurial/dispatch.py >> --- a/mercurial/dispatch.py Tue Dec 06 11:44:49 2016 + >> +++ 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.fsdecode(k):v for k, v in cmdoptions.items()} >> d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) > > Dict comprehension isn't available on Python 2.6. Nice catch, v2 coming. > > I prefer sysstr() here because we know 'k' must be a symbol-like string. We'll > probably need utility functions to convert kwargs between {unicode: x} and > {bytes: x}. Utility functions help in cleaner code, I will add them in pycompat in next version. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH] py3: make keys of keyword arguments strings
On Wed, 07 Dec 2016 10:43:24 +0530, Pulkit Goyal wrote: > # HG changeset patch > # User Pulkit Goyal <7895pul...@gmail.com> > # Date 1481085372 -19800 > # Wed Dec 07 10:06:12 2016 +0530 > # Node ID 60372f5694c6b188fba456cfd269690e84ac645b > # Parent 831d29deed083618bddc2fade7d2a6fe297c896d > 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! Nice! > diff -r 831d29deed08 -r 60372f5694c6 mercurial/dispatch.py > --- a/mercurial/dispatch.py Tue Dec 06 11:44:49 2016 + > +++ 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.fsdecode(k):v for k, v in cmdoptions.items()} > d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) Dict comprehension isn't available on Python 2.6. I prefer sysstr() here because we know 'k' must be a symbol-like string. We'll probably need utility functions to convert kwargs between {unicode: x} and {bytes: x}. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH] py3: make keys of keyword arguments strings
Excerpts from Pulkit Goyal's message of 2016-12-07 10:43:24 +0530: > Also after this patch, `hg version` now runs on Python 3.5. Hurray! LGTM, having `hg version` running is really good news. Congrats! -- ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH] py3: make keys of keyword arguments strings
# HG changeset patch # User Pulkit Goyal <7895pul...@gmail.com> # Date 1481085372 -19800 # Wed Dec 07 10:06:12 2016 +0530 # Node ID 60372f5694c6b188fba456cfd269690e84ac645b # Parent 831d29deed083618bddc2fade7d2a6fe297c896d 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 831d29deed08 -r 60372f5694c6 mercurial/dispatch.py --- a/mercurial/dispatch.py Tue Dec 06 11:44:49 2016 + +++ 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.fsdecode(k):v for k, v in cmdoptions.items()} d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) try: return runcommand(lui, repo, cmd, fullargs, ui, options, d, diff -r 831d29deed08 -r 60372f5694c6 tests/test-check-py3-commands.t --- a/tests/test-check-py3-commands.t Tue Dec 06 11:44:49 2016 + +++ 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 ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH] py3: make keys of keyword arguments strings
# HG changeset patch # User Pulkit Goyal <7895pul...@gmail.com> # Date 1481085372 -19800 # Wed Dec 07 10:06:12 2016 +0530 # Node ID fda5c05c4febd5000b54b1dab52158c66ed07e6e # Parent 831d29deed083618bddc2fade7d2a6fe297c896d 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 831d29deed08 -r fda5c05c4feb mercurial/dispatch.py --- a/mercurial/dispatch.py Tue Dec 06 11:44:49 2016 + +++ 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.fsdecode(k):v for k,v in cmdoptions.items()} d = lambda: util.checksignature(func)(ui, *args, **cmdoptions) try: return runcommand(lui, repo, cmd, fullargs, ui, options, d, diff -r 831d29deed08 -r fda5c05c4feb tests/test-check-py3-commands.t --- a/tests/test-check-py3-commands.t Tue Dec 06 11:44:49 2016 + +++ 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 ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel