[PATCH 1 of 7] templater: define interface for objects which act as iterator of mappings

Yuya Nishihara yuya at tcha.org
Wed Apr 4 14:48:52 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# 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:


More information about the Mercurial-devel mailing list