Mercurial > public > mercurial-scm > hg
comparison mercurial/templater.py @ 28344:ac371d4c007f
templater: drop redundant type conversion when evaluating integer argument
A function argument may be an integer. In this case, it isn't necessary to
convert a value to string and back to integer.
Because an argument may be an arbitrary object (e.g. date tuple), TypeError
should be caught as well.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 14 Feb 2016 12:48:14 +0900 |
parents | a6c2310b3827 |
children | d81437c91a26 |
comparison
equal
deleted
inserted
replaced
28343:a6c2310b3827 | 28344:ac371d4c007f |
---|---|
219 if isinstance(thing, types.GeneratorType): | 219 if isinstance(thing, types.GeneratorType): |
220 thing = stringify(thing) | 220 thing = stringify(thing) |
221 return thing | 221 return thing |
222 | 222 |
223 def evalinteger(context, mapping, arg, err): | 223 def evalinteger(context, mapping, arg, err): |
224 v = evalfuncarg(context, mapping, arg) | |
224 try: | 225 try: |
225 return int(stringify(arg[0](context, mapping, arg[1]))) | 226 return int(v) |
226 except ValueError: | 227 except (TypeError, ValueError): |
227 raise error.ParseError(err) | 228 raise error.ParseError(err) |
228 | 229 |
229 def runinteger(context, mapping, data): | 230 def runinteger(context, mapping, data): |
230 return int(data) | 231 return int(data) |
231 | 232 |