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
The expression x(1,2) > 3 is a boolean expression and as such should return a boolean which indeed it does:
>>>fromjinja2.nativetypesimportNativeEnvironment>>>r=NativeEnvironment().from_string("{%- macro x(a,b) -%}{{- a + b -}}{%- endmacro -%}{{- x(1,2) > 3 -}}").render()
>>>r, type(r)
(False, <class'bool'>)
If the macro returned a string there would be an error like TypeError: '>' not supported between instances of 'str' and 'int'. Can you clarify why you think the macro returns a string?
Hm, indeed, that code works when I try it in another Jinja2 playground. I was using it in the Template editor in Home Assistant, where it does in fact give the error you mention:
So there must be something special about the environment there.
#1511 by @mkrizek added a test that looks like this (formatting mine):
This shows that rendering
[1,2]
in the macro returns an actuallist
from the macro, not a string.According to the first example on https://jinja.palletsprojects.com/en/3.1.x/nativetypes/ I would expect this to work as well:
I would expect the macro to return an
int
, but apparently it returns a string.Environment:
The text was updated successfully, but these errors were encountered: