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

Function fstring_to_object

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

Source from the content-addressed store, hash-verified

507}
508
509pub(super) fn fstring_to_object(
510 vm: &VirtualMachine,
511 source_file: &SourceFile,
512 expression: ast::ExprFString,
513) -> PyObjectRef {
514 let ast::ExprFString {
515 range,
516 mut value,
517 node_index: _,
518 } = expression;
519 let default_part = ast::FStringPart::FString(ast::FString {
520 node_index: Default::default(),
521 range: Default::default(),
522 elements: Default::default(),
523 flags: ast::FStringFlags::empty(),
524 });
525 let mut values = Vec::new();
526 for i in 0..value.as_slice().len() {
527 let part = core::mem::replace(value.iter_mut().nth(i).unwrap(), default_part.clone());
528 match part {
529 ast::FStringPart::Literal(ast::StringLiteral {
530 range,
531 value,
532 flags,
533 node_index: _,
534 }) => {
535 values.push(JoinedStrPart::Constant(Constant::new_str(
536 value,
537 flags.prefix(),
538 range,
539 )));
540 }
541 ast::FStringPart::FString(ast::FString {
542 range: _,
543 elements,
544 flags: _,
545 node_index: _,
546 }) => {
547 for element in ruff_fstring_element_into_iter(elements) {
548 values.push(ruff_fstring_element_to_joined_str_part(element));
549 }
550 }
551 }
552 }
553 let values = normalize_joined_str_parts(values);
554 for part in &values {
555 if let JoinedStrPart::FormattedValue(value) = part
556 && let Some(format_spec) = &value.format_spec
557 {
558 warn_invalid_escape_sequences_in_format_spec(vm, source_file, format_spec.range);
559 }
560 }
561 let c = JoinedStr {
562 range,
563 values: values.into_boxed_slice(),
564 };
565 c.ast_to_object(vm, source_file)
566}

Callers 1

ast_to_objectMethod · 0.85

Calls 15

newFunction · 0.85
prefixMethod · 0.80
ConstantClass · 0.70
replaceFunction · 0.50
lenMethod · 0.45
as_sliceMethod · 0.45
unwrapMethod · 0.45
iter_mutMethod · 0.45

Tested by

no test coverage detected