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

Method slot_new

crates/vm/src/builtins/weakref.rs:44–60  ·  view source on GitHub ↗
(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

42 type Args = WeakNewArgs;
43
44 fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
45 // PyArg_UnpackTuple: only process positional args, ignore kwargs.
46 // Subclass __init__ will handle extra kwargs.
47 let mut positional = args.args.into_iter();
48 let referent = positional
49 .next()
50 .ok_or_else(|| vm.new_type_error("__new__ expected at least 1 argument, got 0"))?;
51 let callback = positional.next();
52 if let Some(_extra) = positional.next() {
53 return Err(vm.new_type_error(format!(
54 "__new__ expected at most 2 arguments, got {}",
55 3 + positional.count()
56 )));
57 }
58 let weak = referent.downgrade_with_typ(callback, cls, vm)?;
59 Ok(weak.into())
60 }
61
62 fn py_new(_cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> {
63 unimplemented!("use slot_new")

Callers

nothing calls this directly

Calls 5

ok_or_elseMethod · 0.80
downgrade_with_typMethod · 0.80
ErrClass · 0.50
into_iterMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected