D3536: json: reject unicode on py2 as well

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Thu May 17 08:12:29 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf5a1aa8c6987: json: reject unicode on py2 as well (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3536?vs=8717&id=8722

REVISION DETAIL
  https://phab.mercurial-scm.org/D3536

AFFECTED FILES
  mercurial/templatefilters.py

CHANGE DETAILS

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -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))



To: martinvonz, #hg-reviewers, indygreg
Cc: yuja, indygreg, mercurial-devel


More information about the Mercurial-devel mailing list