templater: drop hybrid-ness on unwrapvalue()
authorYuya Nishihara <yuya@tcha.org>
Mon, 19 Mar 2018 00:26:55 +0900
changeset 38269 cf8d210dfac4
parent 38268 49ef1539b84e
child 38270 630c62804383
templater: drop hybrid-ness on unwrapvalue() Proxy methods are no longer necessary as list/dict functions go through the wrapped interface.
mercurial/templateutil.py
--- a/mercurial/templateutil.py	Fri Mar 23 22:31:58 2018 +0900
+++ b/mercurial/templateutil.py	Mon Mar 19 00:26:55 2018 +0900
@@ -235,22 +235,12 @@
         return gen
 
     def tovalue(self, context, mapping):
-        # TODO: return self._values and get rid of proxy methods
-        return self
-
-    def __contains__(self, x):
-        return x in self._values
-    def __getitem__(self, key):
-        return self._values[key]
-    def __len__(self):
-        return len(self._values)
-    def __iter__(self):
-        return iter(self._values)
-    def __getattr__(self, name):
-        if name not in (r'get', r'items', r'iteritems', r'iterkeys',
-                        r'itervalues', r'keys', r'values'):
-            raise AttributeError(name)
-        return getattr(self._values, name)
+        # TODO: make it non-recursive for trivial lists/dicts
+        xs = self._values
+        if util.safehasattr(xs, 'get'):
+            return {k: unwrapvalue(context, mapping, v)
+                    for k, v in xs.iteritems()}
+        return [unwrapvalue(context, mapping, x) for x in xs]
 
 class mappable(wrapped):
     """Wrapper for non-list/dict object to support map operation
@@ -259,9 +249,6 @@
     - "{manifest}"
     - "{manifest % '{rev}:{node}'}"
     - "{manifest.rev}"
-
-    Unlike a hybrid, this does not simulate the behavior of the underling
-    value.
     """
 
     def __init__(self, gen, key, value, makemap):