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

Function _template_to_ast_constructor

Lib/annotationlib.py:587–605  ·  view source on GitHub ↗

Convert a `template` instance to a non-literal AST.

(template)

Source from the content-addressed store, hash-verified

585
586
587def _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
608def _template_to_ast_literal(template, parsed):

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…