(zelf: &Py<Self>, args: FuncArgs, vm: &VirtualMachine)
| 2510 | impl Callable for PyType { |
| 2511 | type Args = FuncArgs; |
| 2512 | fn call(zelf: &Py<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult { |
| 2513 | vm_trace!("type_call: {:?}", zelf); |
| 2514 | |
| 2515 | if zelf.is(vm.ctx.types.type_type) { |
| 2516 | let num_args = args.args.len(); |
| 2517 | if num_args == 1 && args.kwargs.is_empty() { |
| 2518 | return Ok(args.args[0].obj_type()); |
| 2519 | } |
| 2520 | if num_args != 3 { |
| 2521 | return Err(vm.new_type_error("type() takes 1 or 3 arguments")); |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | let obj = if let Some(slot_new) = zelf.slots.new.load() { |
| 2526 | slot_new(zelf.to_owned(), args.clone(), vm)? |
| 2527 | } else { |
| 2528 | return Err(vm.new_type_error(format!("cannot create '{}' instances", zelf.slots.name))); |
| 2529 | }; |
| 2530 | |
| 2531 | if !obj.class().fast_issubclass(zelf) { |
| 2532 | return Ok(obj); |
| 2533 | } |
| 2534 | |
| 2535 | if let Some(init_method) = obj.class().slots.init.load() { |
| 2536 | init_method(obj.clone(), args, vm)?; |
| 2537 | } |
| 2538 | Ok(obj) |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | impl AsNumber for PyType { |
no test coverage detected