Mercurial > hg-stable
diff mercurial/templatefuncs.py @ 38255:06d11cd90516
templater: promote getmember() to an interface of wrapped types
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 21 Mar 2018 11:30:21 +0900 |
parents | 12b6ee9e88f3 |
children | 688fbb758ba9 |
line wrap: on
line diff
--- a/mercurial/templatefuncs.py Wed Mar 21 01:39:44 2018 +0900 +++ b/mercurial/templatefuncs.py Wed Mar 21 11:30:21 2018 +0900 @@ -262,12 +262,13 @@ raise error.ParseError(_("get() expects two arguments")) dictarg = evalwrapped(context, mapping, args[0]) - if not util.safehasattr(dictarg, 'getmember'): + key = evalfuncarg(context, mapping, args[1]) + try: + return dictarg.getmember(context, mapping, key) + except error.ParseError as err: # i18n: "get" is a keyword - raise error.ParseError(_("get() expects a dict as first argument")) - - key = evalfuncarg(context, mapping, args[1]) - return dictarg.getmember(context, mapping, key) + hint = _("get() expects a dict as first argument") + raise error.ParseError(bytes(err), hint=hint) @templatefunc('if(expr, then[, else])') def if_(context, mapping, args):