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

Method py_new

crates/vm/src/builtins/interpolation.rs:66–97  ·  view source on GitHub ↗
(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

64 type Args = InterpolationArgs;
65
66 fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
67 let conversion: PyObjectRef = if let Some(s) = args.conversion {
68 let has_flag = s
69 .as_bytes()
70 .iter()
71 .exactly_one()
72 .ok()
73 .is_some_and(|s| matches!(*s, b's' | b'r' | b'a'));
74 if !has_flag {
75 return Err(vm.new_value_error(
76 "Interpolation() argument 'conversion' must be one of 's', 'a' or 'r'",
77 ));
78 }
79 s.into()
80 } else {
81 vm.ctx.none()
82 };
83
84 let expression = args
85 .expression
86 .unwrap_or_else(|| vm.ctx.empty_str.to_owned());
87 let format_spec = args
88 .format_spec
89 .unwrap_or_else(|| vm.ctx.empty_str.to_owned());
90
91 Ok(PyInterpolation {
92 value: args.value,
93 expression,
94 conversion,
95 format_spec,
96 })
97 }
98}
99
100#[derive(FromArgs)]

Callers

nothing calls this directly

Calls 6

okMethod · 0.80
noneMethod · 0.80
ErrClass · 0.50
iterMethod · 0.45
as_bytesMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected