[PATCH 08 of 10] py3: use unicode literals in mdiff.py

Yuya Nishihara yuya at tcha.org
Wed Aug 3 10:06:09 EDT 2016


On Wed, 03 Aug 2016 01:57:30 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1470168805 -19800
> #      Wed Aug 03 01:43:25 2016 +0530
> # Node ID f7cb9b3eeac9c22dc76f6c5976fda488ba992be2
> # Parent  a77a7f6e8bfc90901d829257a782ff11e2bae0f7
> py3: use unicode literals in mdiff.py
> 
> This is a near-sighted solution to unbust mdiff.py importing on Python
> 3. The import was previously failing due to a setattr() using a
> bytes instance on the attribute name.
> 
> The behavior of str vs bytes keys is kinda wonky in Python.
> In Python 2, key names are automagically converted from 1 type
> to the other. e.g. if you set a unicode key then set a str key of
> essentially the same value, the original key gets updated. But
> on Python 3 there can be different keys for "identical" str and
> bytes values! That's why this patch is short-signed: there will
> certainly be consumers looking at the bytes keys of this dict.
> 
> But for now it unblocks importing of this module. And behavior
> is identical in Python 2, so it should be safe.
> 
> diff -r a77a7f6e8bfc -r f7cb9b3eeac9 mercurial/mdiff.py
> --- a/mercurial/mdiff.py	Wed Aug 03 01:39:08 2016 +0530
> +++ b/mercurial/mdiff.py	Wed Aug 03 01:43:25 2016 +0530
> @@ -45,17 +45,17 @@
>      '''
>  
>      defaults = {
> -        'context': 3,
> -        'text': False,
> -        'showfunc': False,
> -        'git': False,
> -        'nodates': False,
> -        'nobinary': False,
> -        'noprefix': False,
> -        'ignorews': False,
> -        'ignorewsamount': False,
> -        'ignoreblanklines': False,
> -        'upgrade': False,
> +        u'context': 3,
> +        u'text': False,
> +        u'showfunc': False,
> +        u'git': False,
> +        u'nodates': False,
> +        u'nobinary': False,
> +        u'noprefix': False,
> +        u'ignorews': False,
> +        u'ignorewsamount': False,
> +        u'ignoreblanklines': False,
> +        u'upgrade': False,
>          }

I found no real problem, but I'm afraid that this could spill unicode objects
out.


More information about the Mercurial-devel mailing list