MCPcopy Index your code
hub / github.com/python/cpython / _template_to_ast_literal

Function _template_to_ast_literal

Lib/annotationlib.py:608–627  ·  view source on GitHub ↗

Convert a `template` instance to a t-string literal AST.

(template, parsed)

Source from the content-addressed store, hash-verified

606
607
608def _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
630def _template_to_ast(template):

Callers 1

_template_to_astFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…