changeset 37276:b4630e332a99

templater: drop unneeded generator from mappable object Per the definition of the show() interface, it can return a bytes.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Mar 2018 20:58:28 +0900
parents 8c84dc8264dc
children 9e8128e84326
files mercurial/templateutil.py
diffstat 1 files changed, 3 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templateutil.py	Sat Mar 17 20:56:42 2018 +0900
+++ b/mercurial/templateutil.py	Sat Mar 17 20:58:28 2018 +0900
@@ -113,15 +113,11 @@
     """
 
     def __init__(self, gen, key, value, makemap):
-        if gen is not None:
-            self._gen = gen  # generator or function returning generator
+        self._gen = gen  # generator or function returning generator
         self._key = key
         self._value = value  # may be generator of strings
         self._makemap = makemap
 
-    def _gen(self):
-        yield pycompat.bytestr(self._value)
-
     def tomap(self):
         return self._makemap(self._key)
 
@@ -131,6 +127,8 @@
     def show(self, context, mapping):
         # TODO: switch gen to (context, mapping) API?
         gen = self._gen
+        if gen is None:
+            return pycompat.bytestr(self._value)
         if callable(gen):
             return gen()
         return gen