diff mercurial/templater.py @ 34536:4c1cfe54c08d

templater: extend dot operator as a short for get(dict, key)
author Yuya Nishihara <yuya@tcha.org>
date Mon, 18 Sep 2017 23:07:17 +0900
parents 78590585c0db
children ee0d74083a22
line wrap: on
line diff
--- a/mercurial/templater.py	Sat Sep 09 19:32:56 2017 +0900
+++ b/mercurial/templater.py	Mon Sep 18 23:07:17 2017 +0900
@@ -463,7 +463,8 @@
         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 @@
         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