changeset 38024:f5a1aa8c6987

json: reject unicode on py2 as well This makes it consistent with the behavior on py3. Differential Revision: https://phab.mercurial-scm.org/D3536
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 11 May 2018 10:36:28 -0700
parents c3fd9a0f8277
children 5046c906b25d
files mercurial/templatefilters.py
diffstat 1 files changed, 2 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Wed May 16 20:22:23 2018 +0900
+++ b/mercurial/templatefilters.py	Fri May 11 10:36:28 2018 -0700
@@ -249,13 +249,9 @@
         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))