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

Method get_special

crates/vm/src/vm/method.rs:90–125  ·  view source on GitHub ↗
(
        obj: &PyObject,
        name: &'static PyStrInterned,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

88 }
89
90 pub(crate) fn get_special<const DIRECT: bool>(
91 obj: &PyObject,
92 name: &'static PyStrInterned,
93 vm: &VirtualMachine,
94 ) -> PyResult<Option<Self>> {
95 let obj_cls = obj.class();
96 let attr = if DIRECT {
97 obj_cls.get_direct_attr(name)
98 } else {
99 obj_cls.get_attr(name)
100 };
101 let func = match attr {
102 Some(f) => f,
103 None => {
104 return Ok(None);
105 }
106 };
107 let meth = if func
108 .class()
109 .slots
110 .flags
111 .has_feature(PyTypeFlags::METHOD_DESCRIPTOR)
112 {
113 Self::Function {
114 target: obj.to_owned(),
115 func,
116 }
117 } else {
118 let obj_cls = obj_cls.to_owned().into();
119 let attr = vm
120 .call_get_descriptor_specific(&func, Some(obj.to_owned()), Some(obj_cls))
121 .unwrap_or(Ok(func))?;
122 Self::Attribute(attr)
123 };
124 Ok(Some(meth))
125 }
126
127 pub fn invoke(self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult {
128 let (func, args) = match self {

Callers

nothing calls this directly

Calls 8

AttributeClass · 0.85
get_direct_attrMethod · 0.80
has_featureMethod · 0.80
SomeClass · 0.50
classMethod · 0.45
get_attrMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected