Convert a `template` instance to a t-string literal AST.
(template, parsed)
| 606 | |
| 607 | |
| 608 | def _template_to_ast_literal(template, parsed): |
| 609 | """Convert a `template` instance to a t-string literal AST.""" |
| 610 | values = [] |
| 611 | interp_count = 0 |
| 612 | for part in template: |
| 613 | match part: |
| 614 | case str(): |
| 615 | values.append(ast.Constant(value=part)) |
| 616 | case _: |
| 617 | interp = ast.Interpolation( |
| 618 | str=part.expression, |
| 619 | value=parsed[interp_count], |
| 620 | conversion=ord(part.conversion) if part.conversion else -1, |
| 621 | format_spec=ast.Constant(value=part.format_spec) |
| 622 | if part.format_spec |
| 623 | else None, |
| 624 | ) |
| 625 | values.append(interp) |
| 626 | interp_count += 1 |
| 627 | return ast.TemplateStr(values=values) |
| 628 | |
| 629 | |
| 630 | def _template_to_ast(template): |
no test coverage detected
searching dependent graphs…