(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine)
| 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") |
nothing calls this directly
no test coverage detected