Hello,
I'm trying to figure how expression like "1 + 2 | float" is supposed to be
evaluated: as "(1 + 2) | float" or "1 + (2 | float)". Let me start with
saying that it's intuitively clear that Jinja2's pipe tries to base on unix
shell pipe, but then it's just intuitive that | operator should have low
priority - first an entire expression ("subcommand with all arg" in unix
shell land) is evaluated, then it's piped thru filter(s).
But reading thru docs, http://jinja.pocoo.org/docs/dev/templates/#filters
doesn't clarify that explicitly. It talks about "variables can be modified
by filters", but what would that mean? Either "variable" is just a
colloquial word, which rather should be "expression", but then its
precedence is unclear. However, if "variable" is a technical term, then it
implies (just implies, doesn't make explicit) that | tights bindly to
primary expressions (because well, foo.bar is not a "variable"). But then
does that section imply that filters cannot be applied to constant values?
(because constants are clearly not variables)
All in all, that intro section on filters (
http://jinja.pocoo.org/docs/dev/templates/#filters) leaves impression of
some magicity of pipe operator. However, later, in
http://jinja.pocoo.org/docs/dev/templates/#other-operators
shade of magicity is gone - it's nothing but an operator among bunch of
others. Except that whole "Expressions" section doesn't say anything about
relative precedence of different operators.
I'm not the only one who gets confused by this matter - see for
example http://stackoverflow.com/a/23249743/496009 which starts with "The
Jinja documentation doesn't specify any precedence rules".
So, may I suggest following documentation changes: 1) "Expressions" section
to be augment with operator precedence table/list; 2) "Filters" intro
section to mention precedence explicitly either, perhaps by giving an
example that "a + b | filter" binds as "a + (b | filter)" and not "(a + b)
| filter" ? Thanks in advance.
Of related question, is there a jinja2 native way to test rendering of a
template - for example, a command-line utility which would be installed by
pip/OS packages and allowed to quickly test a template with particular
(simple) variable bindings, for example "jinja2-render template.tpl foo=1
bar='string'"?
Thanks,
Paul
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.