From patchwork Sun Aug 7 19:54:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [8,of,8] py3: use unicode literals in mdiff.py From: Pulkit Goyal <7895pulkit@gmail.com> X-Patchwork-Id: 16187 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sun, 07 Aug 2016 14:54:41 -0500 # HG changeset patch # User Pulkit Goyal <7895pulkit@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: a bytes-like object is required, not 'str' (line *) (glob) mercurial/unionrepo.py: error importing module: a bytes-like object is required, not 'str' (line *) (glob) mercurial/url.py: error importing module: a bytes-like object is required, not 'str' (line *) (glob) - mercurial/verify.py: error importing: attribute name must be string, not 'bytes' (error at mdiff.py:*) (glob) + mercurial/verify.py: error importing module: a bytes-like object is required, not 'str' (line *) (glob) mercurial/win32.py: error importing module: No module named 'msvcrt' (line *) (glob) mercurial/windows.py: error importing module: No module named '_winreg' (line *) (glob) mercurial/wireproto.py: error importing module: invalid syntax (bundle2.py, line *) (line *) (glob)