Skip to content

Instantly share code, notes, and snippets.

@tomoemon
Last active December 13, 2015 21:09
Show Gist options
  • Save tomoemon/4975511 to your computer and use it in GitHub Desktop.
Save tomoemon/4975511 to your computer and use it in GitHub Desktop.
jinja2 strange operator priority
from jinja2 import Environment
env = Environment()
env.from_string("{% if x is sameas 100 and 1 %}xxx{% else %}yyy{% endif %}").render({"x": 100})
# => yyy
env.from_string("{% if (x is sameas 100) and 1 %}xxx{% else %}yyy{% endif %}").render({"x": 100})
# => xxx (expected)
env.from_string("{% if x is sameas (100 and 1) %}xxx{% else %}yyy{% endif %}").render({"x": 100})
# => yyy (actual)
@tomoemon
Copy link
Author

Jinja2 Documentation about Builtin Tests
http://jinja.pocoo.org/docs/templates/#list-of-builtin-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment