Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonstandard operator precedence #508

Closed
ngaya-ll opened this issue Oct 28, 2015 · 1 comment
Closed

Nonstandard operator precedence #508

ngaya-ll opened this issue Oct 28, 2015 · 1 comment

Comments

@ngaya-ll
Copy link

In most programming languages, operators are grouped into families having equal precedence. In Jinja2's parser, each operator has its own precedence level. This affects the associativity of some expressions.

For example, in Python and Java, *,/, //, and % all have the same precedence. In Jinja2, these operators have different precedence. This means that a given expression may yield different results from expected when evaluated in a Jinja2 template (see example). Jinja2 should follow the common convention to avoid "gotchas" and unintuitive behavior.

Python's operator precedence is documented here. Java's operator precedence is described here.

Example:

{{ 10 * 1 // 2 }}

Expected result:

5

Actual result:

0
@jeffwidman
Copy link
Contributor

Dupe of #119

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants