MCPcopy Index your code
hub / github.com/RustPython/RustPython / template_part_to_element

Function template_part_to_element

crates/vm/src/stdlib/_ast/string.rs:750–788  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    part: TemplateStrPart,
)

Source from the content-addressed store, hash-verified

748}
749
750fn template_part_to_element(
751 vm: &VirtualMachine,
752 part: TemplateStrPart,
753) -> PyResult<ast::InterpolatedStringElement> {
754 match part {
755 TemplateStrPart::Constant(constant) => {
756 let ConstantLiteral::Str { value, .. } = constant.value else {
757 return Err(vm.new_type_error("TemplateStr constant values must be strings"));
758 };
759 Ok(ast::InterpolatedStringElement::Literal(
760 ast::InterpolatedStringLiteralElement {
761 range: constant.range,
762 node_index: Default::default(),
763 value,
764 },
765 ))
766 }
767 TemplateStrPart::Interpolation(interpolation) => {
768 let TStringInterpolation {
769 value,
770 conversion,
771 format_spec,
772 range,
773 ..
774 } = interpolation;
775 let format_spec = joined_str_to_ruff_format_spec(format_spec);
776 Ok(ast::InterpolatedStringElement::Interpolation(
777 ast::InterpolatedElement {
778 range,
779 node_index: Default::default(),
780 expression: value,
781 debug_text: None,
782 conversion,
783 format_spec,
784 },
785 ))
786 }
787 }
788}
789
790// constructor
791impl Node for TemplateStr {

Callers 1

Calls 4

InterpolationClass · 0.85
ErrClass · 0.50
LiteralClass · 0.50

Tested by

no test coverage detected