From patchwork Wed Apr 4 14:48:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 7] templater: define interface for objects which act as iterator of mappings From: Yuya Nishihara X-Patchwork-Id: 30257 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Wed, 04 Apr 2018 23:48:52 +0900 # HG changeset patch # User Yuya Nishihara # Date 1521289310 -32400 # Sat Mar 17 21:21:50 2018 +0900 # Node ID e4dcb782c79b3d7c286a398bc51646c244e0ce9e # Parent e826fe7a08c73ed484bb09d7ea2b2093750cec27 templater: define interface for objects which act as iterator of mappings diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -38,6 +38,10 @@ class wrapped(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod + def itermaps(self): + """Yield each template mapping""" + + @abc.abstractmethod def show(self, context, mapping): """Return a bytes or (possibly nested) generator of bytes representing the underlying object @@ -493,7 +497,7 @@ def _formatfiltererror(arg, filt): def runmap(context, mapping, data): darg, targ = data d = evalrawexp(context, mapping, darg) - if util.safehasattr(d, 'itermaps'): + if isinstance(d, wrapped): diter = d.itermaps() else: try: