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

Method py_new

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

Source from the content-addressed store, hash-verified

409 }
410
411 fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
412 match args.object {
413 OptionalArg::Present(input) => {
414 if let OptionalArg::Present(enc) = args.encoding {
415 let s = vm.state.codec_registry.decode_text(
416 input,
417 enc.as_str(),
418 args.errors.into_option(),
419 vm,
420 )?;
421 Ok(Self::from(s.as_wtf8().to_owned()))
422 } else {
423 let s = input.str(vm)?;
424 Ok(Self::from(s.as_wtf8().to_owned()))
425 }
426 }
427 OptionalArg::Missing => Ok(Self::from(String::new())),
428 }
429 }
430}
431
432impl PyStr {

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
decode_textMethod · 0.80
into_optionMethod · 0.80
as_strMethod · 0.45
to_ownedMethod · 0.45
as_wtf8Method · 0.45
strMethod · 0.45

Tested by

no test coverage detected