[PATCH] templater: check invalid use of list expression properly (issue5920)

Augie Fackler raf at durin42.com
Tue Nov 13 20:00:16 EST 2018


queued, thanks

> On Nov 13, 2018, at 8:39 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1542114930 -32400
> #      Tue Nov 13 22:15:30 2018 +0900
> # Node ID 5c7dff08eea9b3f05995380e612546c9bc7a17ad
> # Parent  526ee887c4d512e4d2812edaef30908eba3fafc4
> templater: check invalid use of list expression properly (issue5920)
> 
> The error message is still cryptic, but it should be better.
> 
> diff --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -374,9 +374,7 @@ def compileexp(exp, context, curmethods)
>     if not exp:
>         raise error.ParseError(_("missing argument"))
>     t = exp[0]
> -    if t in curmethods:
> -        return curmethods[t](exp, context)
> -    raise error.ParseError(_("unknown method '%s'") % t)
> +    return curmethods[t](exp, context)
> 
> # template evaluation
> 
> @@ -496,6 +494,10 @@ def _buildfuncargs(exp, context, curmeth
> def buildkeyvaluepair(exp, content):
>     raise error.ParseError(_("can't use a key-value pair in this context"))
> 
> +def buildlist(exp, context):
> +    raise error.ParseError(_("can't use a list in this context"),
> +                           hint=_('check place of comma and parens'))
> +
> # methods to interpret function arguments or inner expressions (e.g. {_(x)})
> exprmethods = {
>     "integer": lambda e, c: (templateutil.runinteger, e[1]),
> @@ -508,6 +510,7 @@ exprmethods = {
>     "%": buildmap,
>     "func": buildfunc,
>     "keyvalue": buildkeyvaluepair,
> +    "list": buildlist,
>     "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
>     "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
>     "negate": buildnegate,
> diff --git a/tests/test-template-basic.t b/tests/test-template-basic.t
> --- a/tests/test-template-basic.t
> +++ b/tests/test-template-basic.t
> @@ -188,7 +188,8 @@ Call function which takes named argument
> 
>   $ hg debugtemplate '{" "|separate}'
>   $ hg debugtemplate '{("not", "an", "argument", "list")|separate}'
> -  hg: parse error: unknown method 'list'
> +  hg: parse error: can't use a list in this context
> +  (check place of comma and parens)
>   [255]
> 
> Second branch starting at nullrev:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list