jinja icon indicating copy to clipboard operation
jinja copied to clipboard

fix f-string syntax error in code generation

Open sisp opened this issue 1 year ago • 3 comments

I've fixed a bug that caused an f-string syntax error in the template compilation when a template, that imports a macro, contains curly braces in its name. The bug was caused by the code-generation of an f-string in which the template name is inserted, and when the template name contains curly braces and the generated code gets executed, Python treats the curly braces as f-string braces. I've changed the code-generation to construct the string differently, such that the affected substring is not an f-string. Instead, the different substrings are concatenated using the + operator.

  • fixes #1792

Checklist:

  • [x] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • [ ] 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.
  • [ ] 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.

sisp avatar May 26 '23 12:05 sisp

I don't think any of the errors were introduced by this PR.

sisp avatar May 26 '23 12:05 sisp

I've rebased this PR onto the latest state of the 3.1.x branch. All tests are passing except pre-commit.ci - pr, but the reported errors originate from 3.1.x and weren't introduced by this PR.

@davidism (or any other maintainer) – may I ask you for a review? :pray:

sisp avatar Dec 19 '23 08:12 sisp