(
vm: &VirtualMachine,
part: TemplateStrPart,
)
| 748 | } |
| 749 | |
| 750 | fn 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 |
| 791 | impl Node for TemplateStr { |
no test coverage detected