[PATCH 8 of 8] py3: use unicode literals in mdiff.py
Pulkit Goyal
7895pulkit at gmail.com
Sun Aug 7 15:58:31 EDT 2016
Kindly ignore this series, I tried hg push
https://selenic.com/repo/hg-push -r some_changest, and the whole
series got pushed :(
On Mon, Aug 8, 2016 at 1:24 AM, Pulkit Goyal <7895pulkit at gmail.com> 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 --git a/mercurial/mdiff.py b/mercurial/mdiff.py
> --- a/mercurial/mdiff.py
> +++ b/mercurial/mdiff.py
> @@ -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,
> }
>
> def __init__(self, **opts):
> diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
> --- a/tests/test-check-py3-compat.t
> +++ b/tests/test-check-py3-compat.t
> @@ -161,7 +161,7 @@
> mercurial/ui.py: error importing module: <TypeError> a bytes-like object is required, not 'str' (line *) (glob)
> mercurial/unionrepo.py: error importing module: <TypeError> a bytes-like object is required, not 'str' (line *) (glob)
> mercurial/url.py: error importing module: <TypeError> a bytes-like object is required, not 'str' (line *) (glob)
> - mercurial/verify.py: error importing: <TypeError> attribute name must be string, not 'bytes' (error at mdiff.py:*) (glob)
> + mercurial/verify.py: error importing module: <TypeError> a bytes-like object is required, not 'str' (line *) (glob)
> mercurial/win32.py: error importing module: <ImportError> No module named 'msvcrt' (line *) (glob)
> mercurial/windows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
> mercurial/wireproto.py: error importing module: <SyntaxError> invalid syntax (bundle2.py, line *) (line *) (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list