Skip to content

Commit 782e270

Browse files
committed
TemplateStr
1 parent b156108 commit 782e270

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/python_minifier/expression_printer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ def visit_JoinedStr(self, node):
743743

744744
self.printer.fstring(str(python_minifier.f_string.OuterFString(node, pep701=pep701)))
745745

746+
def visit_TemplateStr(self, node):
747+
assert isinstance(node, ast.TemplateStr)
748+
749+
import python_minifier.t_string
750+
751+
self.printer.tstring(str(python_minifier.t_string.TString(node)))
752+
746753
def visit_NamedExpr(self, node):
747754
self._expression(node.target)
748755
self.printer.operator(':=')

src/python_minifier/token_printer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ def fstring(self, s):
181181
self._code += s
182182
self.previous_token = TokenTypes.NonNumberLiteral
183183

184+
def tstring(self, s):
185+
"""Add a template string (t-string) to the output code."""
186+
assert isinstance(s, str)
187+
188+
if self.previous_token in [TokenTypes.Identifier, TokenTypes.Keyword, TokenTypes.SoftKeyword]:
189+
self.delimiter(' ')
190+
191+
self._code += s
192+
self.previous_token = TokenTypes.NonNumberLiteral
193+
184194
def delimiter(self, d):
185195
"""Add a delimiter to the output code."""
186196
assert d in [

0 commit comments

Comments
 (0)