You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unlike Python, chained pow is evaluated left to right. {{ 333 }} is evaluated as (33)3 in Jinja, but would be evaluated as 3(33) in Python. Use parentheses in Jinja to be explicit about what order you want. It is usually preferable to do extended math in Python and pass the results to render rather than doing it in the template.
However the docs also state:
This behavior may be changed in the future to match Python, if it’s possible to introduce an upgrade path.
We should have done it years ago, the longer you wait the more potential there is for someone relying on it. This has come up a few times before, and we've always decided to leave it as-is.
But I have a feeling the only people using ** in templates are doing math, and expect it to work the right way, report it here and it gets closed. So I'm going to change sides and say let's fix it in the next feature release 3.2. Operator precedence should be the same as Python.
Discovered it when working on #1720. Looks like the fix will fix both issues.
Minimal reproducible example
Expected behaviour
I expected exact behaviour as in pure python. We need to start evaluation from left to right.
Environment:
The text was updated successfully, but these errors were encountered: