Patchwork [5,of,8] templater: drop unneeded generator from mappable object

login
register
mail settings
Submitter Yuya Nishihara
Date April 1, 2018, 2:46 a.m.
Message ID <cc616e233d253af1aeb4.1522550762@mimosa>
Download mbox | patch
Permalink /patch/30092/
State Deferred
Headers show

Comments

Yuya Nishihara - April 1, 2018, 2:46 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521287908 -32400
#      Sat Mar 17 20:58:28 2018 +0900
# Node ID cc616e233d253af1aeb4cc2576a38a437c3be95a
# Parent  9a9b1047830a742e914d7085cfd9df34f5577d64
templater: drop unneeded generator from mappable object

Per the definition of the show() interface, it can return a bytes.

Patch

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -108,15 +108,11 @@  class mappable(wrapped):
     """
 
     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)
 
@@ -126,6 +122,8 @@  class mappable(wrapped):
     def show(self, context):
         # TODO: switch gen to context-based API?
         gen = self._gen
+        if gen is None:
+            return pycompat.bytestr(self._value)
         if callable(gen):
             return gen()
         return gen