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

Function getattr

crates/vm/src/stdlib/builtins.rs:621–639  ·  view source on GitHub ↗
(
        obj: PyObjectRef,
        attr: PyObjectRef,
        default: OptionalArg<PyObjectRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

619
620 #[pyfunction]
621 fn getattr(
622 obj: PyObjectRef,
623 attr: PyObjectRef,
624 default: OptionalArg<PyObjectRef>,
625 vm: &VirtualMachine,
626 ) -> PyResult {
627 let attr = attr.try_to_ref::<PyStr>(vm).map_err(|_e| {
628 vm.new_type_error(format!(
629 "attribute name must be string, not '{}'",
630 attr.class().name()
631 ))
632 })?;
633
634 if let OptionalArg::Present(default) = default {
635 Ok(vm.get_attribute_opt(obj, attr)?.unwrap_or(default))
636 } else {
637 obj.get_attr(attr, vm)
638 }
639 }
640
641 #[pyfunction]
642 fn globals(vm: &VirtualMachine) -> PyDictRef {

Callers 15

__getattr__Method · 0.85
shutdownMethod · 0.85
runFunction · 0.85
update_wrapperFunction · 0.85
total_orderingFunction · 0.85
__get__Method · 0.85
__isabstractmethod__Method · 0.85
_unwrap_partialmethodFunction · 0.85
registerFunction · 0.85
singledispatchFunction · 0.85
__isabstractmethod__Method · 0.85
__call__Method · 0.85

Calls 2

get_attribute_optMethod · 0.80
get_attrMethod · 0.45

Tested by 15

_extract_future_flagsFunction · 0.68
_load_testfileFunction · 0.68
findMethod · 0.68
_findMethod · 0.68
_get_testMethod · 0.68
_find_linenoMethod · 0.68
test_streamreaderMethod · 0.68
test_streamwriterMethod · 0.68
test_allMethod · 0.68
run_perfMethod · 0.68
__annotations__Method · 0.68
stderr_to_parser_errorFunction · 0.68