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

Method py_new

crates/vm/src/stdlib/_operator.rs:396–414  ·  view source on GitHub ↗
(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

394 type Args = FuncArgs;
395
396 fn py_new(_cls: &Py<PyType>, args: Self::Args, vm: &VirtualMachine) -> PyResult<Self> {
397 let n_attr = args.args.len();
398 // Check we get no keyword and at least one positional.
399 if !args.kwargs.is_empty() {
400 return Err(vm.new_type_error("attrgetter() takes no keyword arguments"));
401 }
402 if n_attr == 0 {
403 return Err(vm.new_type_error("attrgetter expected 1 argument, got 0."));
404 }
405 let mut attrs = Vec::with_capacity(n_attr);
406 for o in args.args {
407 if let Ok(r) = o.try_into_value(vm) {
408 attrs.push(r);
409 } else {
410 return Err(vm.new_type_error("attribute name must be a string"));
411 }
412 }
413 Ok(Self { attrs })
414 }
415 }
416
417 impl Callable for PyAttrGetter {

Callers

nothing calls this directly

Calls 5

try_into_valueMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected