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

Method slot_new

crates/vm/src/builtins/bool.rs:83–94  ·  view source on GitHub ↗
(zelf: PyTypeRef, args: FuncArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

81 type Args = OptionalArg<PyObjectRef>;
82
83 fn slot_new(zelf: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
84 let x: Self::Args = args.bind(vm)?;
85 if !zelf.fast_isinstance(vm.ctx.types.type_type) {
86 let actual_class = zelf.class();
87 let actual_type = &actual_class.name();
88 return Err(vm.new_type_error(format!(
89 "requires a 'type' object but received a '{actual_type}'"
90 )));
91 }
92 let val = x.map_or(Ok(false), |val| val.try_to_bool(vm))?;
93 Ok(vm.ctx.new_bool(val).into())
94 }
95
96 fn py_new(_cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> {
97 unimplemented!("use slot_new")

Callers

nothing calls this directly

Calls 7

fast_isinstanceMethod · 0.80
try_to_boolMethod · 0.80
ErrClass · 0.50
bindMethod · 0.45
classMethod · 0.45
nameMethod · 0.45
new_boolMethod · 0.45

Tested by

no test coverage detected