Comments
Patch
@@ -76,6 +76,7 @@ The dot operator can be used as a shorth
- ``expr.member`` is roughly equivalent to ``expr % "{member}"`` if ``expr``
returns a non-list/dict. The returned value is not stringified.
+- ``dict.key`` is identical to ``get(dict, "key")``.
Aliases
=======
@@ -463,7 +463,8 @@ def runmember(context, mapping, data):
lm = mapping.copy()
lm.update(d.tomap())
return runsymbol(context, lm, memb)
- # TODO: d.get(memb) if dict-like?
+ if util.safehasattr(d, 'get'):
+ return _getdictitem(d, memb)
sym = findsymbolicname(darg)
if sym:
@@ -751,6 +752,9 @@ def get(context, mapping, args):
raise error.ParseError(_("get() expects a dict as first argument"))
key = evalfuncarg(context, mapping, args[1])
+ return _getdictitem(dictarg, key)
+
+def _getdictitem(dictarg, key):
val = dictarg.get(key)
if val is None:
return
@@ -3184,6 +3184,8 @@ Test evaluation of dot operator:
$ hg log -R latesttag -l1 -T '{min(revset("0:9")).node}\n'
ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
+ $ hg log -R latesttag -r0 -T '{extras.branch}\n'
+ default
$ hg log -R latesttag -l1 -T '{author.invalid}\n'
hg: parse error: keyword 'author' has no member