# HG changeset patch # User Martin von Zweigbergk # Date 2018-05-11 17:36:28 # Node ID f5a1aa8c69877c5560af9e058f3a4f75022f25e5 # Parent c3fd9a0f8277a4abbc709a91f642f841bad1cc62 json: reject unicode on py2 as well This makes it consistent with the behavior on py3. Differential Revision: https://phab.mercurial-scm.org/D3536 diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -249,13 +249,9 @@ def json(obj, paranoid=True): return pycompat.bytestr(obj) elif isinstance(obj, bytes): return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid) - elif isinstance(obj, str): - # This branch is unreachable on Python 2, because bytes == str - # and we'll return in the next-earlier block in the elif - # ladder. On Python 3, this helps us catch bugs before they - # hurt someone. + elif isinstance(obj, type(u'')): raise error.ProgrammingError( - 'Mercurial only does output with bytes on Python 3: %r' % obj) + 'Mercurial only does output with bytes: %r' % obj) elif util.safehasattr(obj, 'keys'): out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid), json(v, paranoid))