jinja icon indicating copy to clipboard operation
jinja copied to clipboard

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

Open Zocker1999NET opened this issue 3 years ago • 0 comments

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.

  • fixes #100
    • the issue is already closed, however it wasn't really fixed for macro signatures

Checklist:

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

Zocker1999NET avatar Aug 28 '22 14:08 Zocker1999NET