From patchwork Sun Mar 25 05:15:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6, of, 7] templater: extract unwrapinteger() function from evalinteger() From: Yuya Nishihara X-Patchwork-Id: 29843 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sun, 25 Mar 2018 14:15:53 +0900 # HG changeset patch # User Yuya Nishihara # Date 1521804852 -32400 # Fri Mar 23 20:34:12 2018 +0900 # Node ID b5bdcfbf663e1fa1d7c2004a0ef6b3172cc8eff9 # Parent 974b91e77122678881e9618d1682cfe0cf02d367 templater: extract unwrapinteger() function from evalinteger() diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -318,9 +318,12 @@ def evalboolean(context, mapping, arg): return bool(stringify(thing)) def evalinteger(context, mapping, arg, err=None): - v = evalfuncarg(context, mapping, arg) + return unwrapinteger(evalrawexp(context, mapping, arg), err) + +def unwrapinteger(thing, err=None): + thing = _unwrapvalue(thing) try: - return int(v) + return int(thing) except (TypeError, ValueError): raise error.ParseError(err or _('not an integer'))