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

Method call

crates/vm/src/builtins/type.rs:2512–2539  ·  view source on GitHub ↗
(zelf: &Py<Self>, args: FuncArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2510impl 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
2542impl AsNumber for PyType {

Callers 15

__add__Method · 0.45
merge_objectMethod · 0.45
missing_optMethod · 0.45
getattr_innerMethod · 0.45
__annotations__Method · 0.45
reprMethod · 0.45
string_to_forwardrefFunction · 0.45
slot_newMethod · 0.45
type_slot_namesFunction · 0.45
__reduce_ex__Method · 0.45
object_getstateFunction · 0.45
common_reduceFunction · 0.45

Calls 10

isMethod · 0.80
fast_issubclassMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45
obj_typeMethod · 0.45
loadMethod · 0.45
to_ownedMethod · 0.45
cloneMethod · 0.45
classMethod · 0.45

Tested by

no test coverage detected