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

Method slot_new

crates/vm/src/builtins/str.rs:396–409  ·  view source on GitHub ↗
(cls: PyTypeRef, func_args: FuncArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

394 type Args = StrArgs;
395
396 fn slot_new(cls: PyTypeRef, func_args: FuncArgs, vm: &VirtualMachine) -> PyResult {
397 // Optimization: return exact str as-is (only when no encoding/errors provided)
398 if cls.is(vm.ctx.types.str_type)
399 && func_args.args.len() == 1
400 && func_args.kwargs.is_empty()
401 && func_args.args[0].class().is(vm.ctx.types.str_type)
402 {
403 return Ok(func_args.args[0].clone());
404 }
405
406 let args: Self::Args = func_args.bind(vm)?;
407 let payload = Self::py_new(&cls, args, vm)?;
408 payload.into_ref_with_type(vm, cls).map(Into::into)
409 }
410
411 fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
412 match args.object {

Callers

nothing calls this directly

Calls 8

isMethod · 0.80
into_ref_with_typeMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45
classMethod · 0.45
cloneMethod · 0.45
bindMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected