[PATCH 3 of 3] py3: switch to unicode/bytes in pycompat.py

Yuya Nishihara yuya at tcha.org
Sun Aug 14 02:37:44 UTC 2016


On Sat, 13 Aug 2016 06:08:26 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1471048490 -19800
> #      Sat Aug 13 06:04:50 2016 +0530
> # Node ID 9a350943e42d8969e52a0001a806938aa8e815e1
> # Parent  1141751d3fbffc136a0afd6103c43532220f337d
> py3: switch to unicode/bytes in pycompat.py
> 
> replace() requires unicode, so switching to unicodes as the arguments will be
> converted to bytes by the transformer.

bytes also provides replace().

https://docs.python.org/3/library/stdtypes.html#bytes.replace

> --- a/mercurial/pycompat.py	Sat Aug 13 04:21:42 2016 +0530
> +++ b/mercurial/pycompat.py	Sat Aug 13 06:04:50 2016 +0530
> @@ -43,7 +43,8 @@
>      """
>      for item in items:
>          try:
> -            lcase = item.replace('_', '').lower()
> +            item = item.decode('latin1')
> +            lcase = item.replace(u'_', u'').lower()
>              setattr(alias, lcase, getattr(origin, item))

This change seems okay, but I guess we'll need setattr/getattr wrappers
which support both bytes and unicode.

Any thoughts?



More information about the Mercurial-devel mailing list