Convert a `template` instance to a non-literal AST.
(template)
| 585 | |
| 586 | |
| 587 | def _template_to_ast_constructor(template): |
| 588 | """Convert a `template` instance to a non-literal AST.""" |
| 589 | args = [] |
| 590 | for part in template: |
| 591 | match part: |
| 592 | case str(): |
| 593 | args.append(ast.Constant(value=part)) |
| 594 | case _: |
| 595 | interp = ast.Call( |
| 596 | func=ast.Name(id="Interpolation"), |
| 597 | args=[ |
| 598 | ast.Constant(value=part.value), |
| 599 | ast.Constant(value=part.expression), |
| 600 | ast.Constant(value=part.conversion), |
| 601 | ast.Constant(value=part.format_spec), |
| 602 | ] |
| 603 | ) |
| 604 | args.append(interp) |
| 605 | return ast.Call(func=ast.Name(id="Template"), args=args, keywords=[]) |
| 606 | |
| 607 | |
| 608 | def _template_to_ast_literal(template, parsed): |
no test coverage detected
searching dependent graphs…