You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
jinjafmt passes jinja to black, but jinja allows some things that python does not. Specifically, variables (esp. macro arguments) can have names that are reserved words. For example:
This is valid jinja and dbt sql (from gitlab's project), but from and except are both reserved words in python. Running black -c "from" returns error: cannot format <string>: Cannot parse: 1:4: from
Right now jinjafmt no-ops in these situations, but it wouldn't be that hard to replace these reserved words (followed by an eq, e.g. from=) with a sentinel (e.g., from__sqlfmt__=), format that, and then replace the sentinel with the keyword again. There are 33 reserved words in python
The text was updated successfully, but these errors were encountered:
tconbeer
changed the title
jinjafmt chokes on python reserved words that are allowed in jinja
Provide workaround for jinja macros that use reserved words as arg names
May 5, 2022
This could also provide a solution to #155 -- return is a reserved word, but jinja allows it as a function name. So we'd probably want to replace reserved words followed by parens, in addition to equals
tconbeer
changed the title
Provide workaround for jinja macros that use reserved words as arg names
Provide workaround for jinja macros that use reserved words
May 5, 2022
Describe the bug
jinjafmt passes jinja to black, but jinja allows some things that python does not. Specifically, variables (esp. macro arguments) can have names that are reserved words. For example:
This is valid jinja and dbt sql (from gitlab's project), but
from
andexcept
are both reserved words in python. Runningblack -c "from"
returnserror: cannot format <string>: Cannot parse: 1:4: from
Right now jinjafmt no-ops in these situations, but it wouldn't be that hard to replace these reserved words (followed by an eq, e.g.
from=
) with a sentinel (e.g.,from__sqlfmt__=
), format that, and then replace the sentinel with the keyword again. There are 33 reserved words in pythonThe text was updated successfully, but these errors were encountered: