AI spam#2188
Closed
rumitvn wants to merge 1 commit into
Closed
Conversation
The template Expressions section described each operator group but never stated how they combine. Add an 'Operator Precedence' subsection listing all operators from lowest to highest binding (verified against the parser in src/jinja2/parser.py), noting that all binary operators are left-associative, that '**' is left-associative (unlike Python), and that filters/tests bind tighter than binary operators -- the common '[3] + [2, 1] | sort' surprise. Closes pallets#1755 Closes pallets#379
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1755
Closes #379
The Expressions section of the template docs documents each operator group (Math, Comparisons, Logic, Other Operators) but never explains how they combine when mixed. This adds an Operator Precedence subsection.
What's added
src/jinja2/parser.py(parse_condexpr→parse_or→parse_and→parse_not→parse_compare→parse_math1→parse_concat→parse_math2→parse_pow→parse_unary→ postfix/filter).**is left-associative in Jinja (unlike Python):{{ 3 ** 3 ** 3 }}→(3 ** 3) ** 3.{{ [3] + [2, 1] | sort }}parses as[3] + ([2, 1] | sort)→[3, 1, 2], with parentheses as the fix.Verification
Rendered the examples against Jinja 3.1.x to confirm the documented results:
{{ [3] + [2, 1] | sort }}→[3, 1, 2]{{ ([3] + [2, 1]) | sort }}→[1, 2, 3]{{ 3 ** 3 ** 3 }}→19683(=(3**3)**3)Docs-only change. Closes the two long-standing requests (#1755, #379) for documenting precedence/associativity.