NativeEnvironment casts integer strings to integer -- intended behavior?
rrauenza opened this issue · comments
Rich Rauenzahn commented
When using NativeEnvironment, jinja seems to convert strings that look like integers to integers.
>>> import jinja2.nativetypes
>>> env = jinja2.nativetypes.NativeEnvironment()
>>> result = env.from_string('{{ x }}').render(x=2)
>>> type(result)
<class 'int'>
>>> result = env.from_string('{{ x }}').render(x='2')
>>> type(result)
<class 'int'>
>>> type(env.from_string('{{ x|string}}').render(x='2'))
<class 'int'>
I would expect in the second case that jinja would preserve that x is a string. Is this behavior intentional?
Environment:
- Python version: 3.12.0
- Jinja version: 3.1.2
(also does it with float like strings... and bools...)
David Lord commented
Yes, this is intended.
Rich Rauenzahn commented
Is this already exposed in the docs? I didn't see it in the NativeEnvironment
docs and could propose a change there if that would be helpful.