templatefilters: use list comprehension in json()
authorYuya Nishihara <yuya@tcha.org>
Sun, 02 Apr 2017 11:54:24 +0900
changeset 31784 47925b63be70
parent 31783 8d9eafe01111
child 31785 654e9a1c8a6c
templatefilters: use list comprehension in json() Not important, but the code slightly looks better.
mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Sun Apr 02 11:51:25 2017 +0900
+++ b/mercurial/templatefilters.py	Sun Apr 02 11:54:24 2017 +0900
@@ -230,15 +230,11 @@
     elif isinstance(obj, str):
         return '"%s"' % encoding.jsonescape(obj, paranoid=True)
     elif util.safehasattr(obj, 'keys'):
-        out = []
-        for k, v in sorted(obj.iteritems()):
-            s = '%s: %s' % (json(k), json(v))
-            out.append(s)
+        out = ['%s: %s' % (json(k), json(v))
+               for k, v in sorted(obj.iteritems())]
         return '{' + ', '.join(out) + '}'
     elif util.safehasattr(obj, '__iter__'):
-        out = []
-        for i in obj:
-            out.append(json(i))
+        out = [json(i) for i in obj]
         return '[' + ', '.join(out) + ']'
     else:
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)