changeset 38269:cf8d210dfac4

templater: drop hybrid-ness on unwrapvalue() Proxy methods are no longer necessary as list/dict functions go through the wrapped interface.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 19 Mar 2018 00:26:55 +0900
parents 49ef1539b84e
children 630c62804383
files mercurial/templateutil.py
diffstat 1 files changed, 6 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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):