Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Tuples #660

Closed
tjsmith-meta opened this issue Dec 18, 2024 · 2 comments
Closed

Support for Tuples #660

tjsmith-meta opened this issue Dec 18, 2024 · 2 comments
Labels
needs-more-information Further information is requested

Comments

@tjsmith-meta
Copy link

tjsmith-meta commented Dec 18, 2024

Description

I encountered that Tuples behaved differently in MiniJinja and then noticed that it is indeed documented that they aren't supported.
https://github.com/mitsuhiko/minijinja/blob/main/COMPATIBILITY.md#tuples

Here's an example.

Input template

{% set foo = ('bar','baz') %}
{{ foo }}

Python Jinja2 output

('bar', 'baz')

MiniJinja output

["bar", "baz"]

Edit: Note that lists also render slightly differently in MiniJinja compared to Python Jinja2. Python Jinja2 renders string elements/entries in lists (and tuples) with single quotes, whereas MiniJinja renders string elements/entries in lists with double quotes. See the example above where Python Jinja2 output has single quotes and MiniJinja output has double quotes.

Reproduction steps

  1. Feed the input template through Python Jinja2
  2. Feed the input template through MiniJinja
  3. See that the results are not the same

What did you expect

Would love to see Tuples supported at parity in MiniJinja with Python Jinja2. Is this a technically complex / challenging to achieve, or has there just not been strong enough motivation yet for parity with Python Jinja2 for this?

@mitsuhiko
Copy link
Owner

Jinja2 never really defined how these things render, it's whatever the underlying thing in Python does. Since most code does not directly emit values and look at their representation the differences between tuples and lists in templates are not particularly meaningful.

MiniJinja does support the creation of lists via tuple literals:

$ minijinja-cli -t '{{ ("Hello",) }}'
["Hello"]

It's not clear to me that it makes sense to create a lot of complexity in MiniJinja to tell these things apart given that they basically behave the same in the context of the engine.

@mitsuhiko mitsuhiko added the needs-more-information Further information is requested label Dec 22, 2024
@mitsuhiko
Copy link
Owner

Going to close this due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-information Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants