From patchwork Tue Apr 3 15:40:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5,of,8,V2] templater: drop unneeded generator from mappable object From: Yuya Nishihara X-Patchwork-Id: 30166 Message-Id: <82d9c4a417c425734bb7.1522770007@mimosa> To: mercurial-devel@mercurial-scm.org Date: Wed, 04 Apr 2018 00:40:07 +0900 # HG changeset patch # User Yuya Nishihara # Date 1521287908 -32400 # Sat Mar 17 20:58:28 2018 +0900 # Node ID 82d9c4a417c425734bb7db227d7c648be8b2d94a # Parent 2f4dc45b1eba20fbbbc80c59e2fcb2777eb68a7d templater: drop unneeded generator from mappable object Per the definition of the show() interface, it can return a bytes. diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -113,15 +113,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) @@ -131,6 +127,8 @@ class mappable(wrapped): 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