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

login
register
mail settings
Submitter Yuya Nishihara
Date April 4, 2018, 2:48 p.m.
Message ID <e4dcb782c79b3d7c286a.1522853332@mimosa>
Download mbox | patch
Permalink /patch/30257/
State Accepted
Headers show

Comments

Yuya Nishihara - April 4, 2018, 2:48 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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

Patch

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: