changeset 31781:47925b63be70

templatefilters: use list comprehension in json() Not important, but the code slightly looks better.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 02 Apr 2017 11:54:24 +0900
parents 8d9eafe01111
children 654e9a1c8a6c
files mercurial/templatefilters.py
diffstat 1 files changed, 3 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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__)