[PATCH 5 of 7] py3: workaround to prevent switching kwargs keys between str and bytes

Yuya Nishihara yuya at tcha.org
Sun Jun 18 02:21:08 EDT 2017


On Sat, 17 Jun 2017 18:15:23 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1497692808 -19800
> #      Sat Jun 17 15:16:48 2017 +0530
> # Node ID 48ef02400b59a6d9d250627d0e5f60e85c90cb06
> # Parent  e95901baf03f983af8163a1d848233b29629d97b
> py3: workaround to prevent switching kwargs keys between str and bytes
> 
> We are getting kwargs variable as keyword argument here, hence it keys must be
> str. Also we need to pass that as keyword argument again, so its better to add
> a r'' at few places instead of converting first to bytes and then to str.
> 
> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -1585,12 +1585,12 @@
>      usebundle2 = bundle2requested(bundlecaps)
>      # bundle10 case
>      if not usebundle2:
> -        if bundlecaps and not kwargs.get('cg', True):
> +        if bundlecaps and not kwargs.get(r'cg', True):
>              raise ValueError(_('request for bundle10 must include changegroup'))
>  
>          if kwargs:
> -            raise ValueError(_('unsupported getbundle arguments: %s')
> -                             % ', '.join(sorted(kwargs.keys())))
> +            raise ValueError(_(r'unsupported getbundle arguments: %s')
> +                             % r', '.join(sorted(kwargs.keys())))

I'm not sure if this ValueError is intended to be caught somewhere. If this
is just for sanity check, _() should be removed. If not, we'll have to use
more specific error class and put bytes in it.

Anybody know the detail?


More information about the Mercurial-devel mailing list