Skip to content

Commit

Permalink
fix(formatter): fixed formatting on functions that used python keywor…
Browse files Browse the repository at this point in the history
…ds as the param name

closes #756
  • Loading branch information
christopherpickering committed Sep 18, 2023
1 parent 5a32bb3 commit 183a7c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/djlint/formatter/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ def format_data(config: Config, contents: str, tag_size: int, leading_space) ->
except:
# was not json.. try to eval as set
try:
evaluated = str(eval(contents))
# if contents is a python keyword, do not evaluate it.
evaluated = (
str(eval(contents)) if contents not in ["object"] else contents
)
# need to unwrap the eval
contents = (
evaluated[1:-1]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_nunjucks/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
({}),
id="broken",
),
pytest.param(
("{{ url(object) }}"),
# https://github.com/Riverside-Healthcare/djLint/issues/756
("{{ url(object) }}\n"),
({}),
id="function param is python keyword",
),
]


Expand Down

0 comments on commit 183a7c0

Please sign in to comment.