Skip to content

Provide workaround for jinja macros that use reserved words #177

Closed
@tconbeer

Description

@tconbeer

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:

{{ dbt_utils.star(from=ref('snowplow_page_views_30'), except=fields_to_exclude|upper) }}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions