[PATCH 5 of 5] templater: resolve type of dict key in getmember()
Yuya Nishihara
yuya at tcha.org
Tue Jun 5 09:18:59 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1525405395 -32400
# Fri May 04 12:43:15 2018 +0900
# Node ID 2002b2699cf6066f8965d84aa15a97d6c4df1b2f
# Parent c30ef16679c1fa6fead795a0ccadd7dced41f408
templater: resolve type of dict key in getmember()
This seems more correct and is consistent with the future wrapped.contains()
function, where a key type has to be resolved depending on a container type.
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -714,6 +714,7 @@ class sessionvars(templateutil.wrapped):
return sessionvars(copy.copy(self._vars), self._start)
def getmember(self, context, mapping, key):
+ key = templateutil.unwrapvalue(context, mapping, key)
return self._vars.get(key)
def itermaps(self, context):
diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py
--- a/mercurial/templatefuncs.py
+++ b/mercurial/templatefuncs.py
@@ -262,7 +262,7 @@ def get(context, mapping, args):
raise error.ParseError(_("get() expects two arguments"))
dictarg = evalwrapped(context, mapping, args[0])
- key = evalfuncarg(context, mapping, args[1])
+ key = evalrawexp(context, mapping, args[1])
try:
return dictarg.getmember(context, mapping, key)
except error.ParseError as err:
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -41,6 +41,7 @@ class wrapped(object):
def getmember(self, context, mapping, key):
"""Return a member item for the specified key
+ The key argument may be a wrapped object.
A returned object may be either a wrapped object or a pure value
depending on the self type.
"""
@@ -147,6 +148,7 @@ class hybrid(wrapped):
# TODO: maybe split hybrid list/dict types?
if not util.safehasattr(self._values, 'get'):
raise error.ParseError(_('not a dictionary'))
+ key = unwrapastype(context, mapping, key, self.keytype)
return self._wrapvalue(key, self._values.get(key))
def _wrapvalue(self, key, val):
More information about the Mercurial-devel
mailing list