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

Function tstring_to_object

crates/vm/src/stdlib/_ast/string.rs:925–957  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    source_file: &SourceFile,
    expression: ast::ExprTString,
)

Source from the content-addressed store, hash-verified

923}
924
925pub(super) fn tstring_to_object(
926 vm: &VirtualMachine,
927 source_file: &SourceFile,
928 expression: ast::ExprTString,
929) -> PyObjectRef {
930 let ast::ExprTString {
931 range,
932 mut value,
933 node_index: _,
934 } = expression;
935 let default_tstring = ast::TString {
936 node_index: Default::default(),
937 range: Default::default(),
938 elements: Default::default(),
939 flags: ast::TStringFlags::empty(),
940 };
941 let mut values = Vec::new();
942 for i in 0..value.as_slice().len() {
943 let tstring = core::mem::replace(value.iter_mut().nth(i).unwrap(), default_tstring.clone());
944 for element in ruff_fstring_element_into_iter(tstring.elements) {
945 values.push(ruff_tstring_element_to_template_str_part(
946 element,
947 source_file,
948 ));
949 }
950 }
951 let values = normalize_template_str_parts(values);
952 let c = TemplateStr {
953 range,
954 values: values.into_boxed_slice(),
955 };
956 c.ast_to_object(vm, source_file)
957}

Callers 1

ast_to_objectMethod · 0.85

Calls 12

newFunction · 0.85
replaceFunction · 0.50
lenMethod · 0.45
as_sliceMethod · 0.45
unwrapMethod · 0.45
iter_mutMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
ast_to_objectMethod · 0.45

Tested by

no test coverage detected