[PATCH 04 of 10] py3: use unicode literals in pycompat.py

Yuya Nishihara yuya at tcha.org
Wed Aug 3 09:43:02 EDT 2016


On Wed, 03 Aug 2016 01:57:26 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1470165929 -19800
> #      Wed Aug 03 00:55:29 2016 +0530
> # Node ID bed55202ebb207a4a7a532135c808e2b62ec6ac8
> # Parent  184be5c73cededc590bca889b6c17889345e1039
> py3: use unicode literals in pycompat.py
           ^^^^^^^^^^^^^^^^
Nit: strictly speaking, this patch doesn't (always) use unicode literals.

> The items list literals later in the file are using string literals.
> These will get rewritten to bytes literals courtesy of our module
> importer. We add some code to convert them back to str and use the
> appropriate type for arguments to .replace().
> 
> diff -r 184be5c73ced -r bed55202ebb2 mercurial/pycompat.py
> --- a/mercurial/pycompat.py	Wed Aug 03 00:45:11 2016 +0530
> +++ b/mercurial/pycompat.py	Wed Aug 03 00:55:29 2016 +0530
> @@ -42,8 +42,10 @@
>      copies items from origin to alias
>      """
>      def hgcase(item):
> -        return item.replace('_', '').lower()
> +        return item.replace(u'_', u'').lower()
>      for item in items:
> +        if not isinstance(item, str):
> +            item = item.decode(u'latin1')

If _alias() expects a list of bytes items, I'd rather do item.decode() without
checking its type.

>          try:
>              setattr(alias, hgcase(item), getattr(origin, item))


More information about the Mercurial-devel mailing list