Improve support for trailing commas in macro signatures, calls & with statements #1712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.