Skip to content

Fix and operator to return operands, not bools#90

Open
theadamdanielsson wants to merge 1 commit into
google:mainfrom
theadamdanielsson:fix-and-operator-operands
Open

Fix and operator to return operands, not bools#90
theadamdanielsson wants to merge 1 commit into
google:mainfrom
theadamdanielsson:fix-and-operator-operands

Conversation

@theadamdanielsson

Copy link
Copy Markdown

and coerces its result to a bool instead of returning the operand — or already does the right thing, so this just makes and match it (and Jinja2/Python).

{{ 'abc' and 'def' }}       minja: True   jinja2: def
{{ (cond and x) or y }}     minja: True   jinja2: x

The (cond and x) or y ternary idiom is where this bites. Boolean context (if a and b) is unaffected, which is why it's gone unnoticed. Fix mirrors the or branch. Added a syntax test for the value-context case; the rest of the suite is unchanged (locally the only failures are the gated meta-llama fetches returning 401s, unrelated to this).

`and` coerced its result to a bool instead of returning the operand,
unlike `or`. This breaks the `(cond and x) or y` value idiom, which
renders True/False instead of x/y. Mirror the `or` branch so `and`
matches Jinja2/Python short-circuit semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant