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

Improve support for trailing commas in macro signatures, calls & with statements #1712

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Zocker1999NET
Copy link

@Zocker1999NET Zocker1999NET commented Aug 28, 2022

This change improves support for trailing commas on macros & with statements by adding tests for already supported trailing commas and adding support & tests for "new" trailing commas.

The support for trailing commas is implemented as follows: By checking at the beginning of a loop but after parsing a comma if the current statement is already closed and ignoring/accepting this, trailing commas become supported. This technique is already used by other parsers in Jinja (e.g. for list & dictionaries). It was copied from other implementations already comitted here and from @njl's implemention from #107, which was probably not merged due to the misunderstanding that #100 was already fixed.

I took the freedom to add support for trailing commas in with statements here as well without creating a concrete issue before. I hope that's okay, otherwise I'm willing to open an issue if one is required. I can also split this change from this PR if that is required.

I also commented the code which adds support for trailing spaces for lists & dictionaries so these are explained like other similar code already is.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

Zocker1999NET and others added 7 commits August 28, 2022 15:59
was missing for:
- parse_list
- parse_dict
- to test already added support for trailing commas in macro arguments

Original source: njl@7b2f718
- to test already supported trailing comma on macro call arguments
- to test newly supported trailing commas in macro signatures

Original source: njl@7b2f718
- to test support for trailing commas in with statements
for both support for trailing commas for
- macro signatures
- with statements
@Zocker1999NET Zocker1999NET marked this pull request as ready for review August 28, 2022 14:59
Zocker1999NET added a commit to Zocker1999NET/jinja that referenced this pull request Nov 6, 2022
Zocker1999NET added a commit to Zocker1999NET/jinja that referenced this pull request Nov 6, 2022
for both support for trailing commas for
- macro signatures
- with statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TemplateSyntaxError: expected token 'name', got ')'
3 participants