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

Method lookup_special

crates/vm/src/protocol/object.rs:793–808  ·  view source on GitHub ↗

Equivalent to CPython's _PyObject_LookupSpecial Looks up a special method in the type's MRO without checking instance dict. Returns None if not found (masking AttributeError like CPython).

(&self, attr: &Py<PyStr>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

791 /// Looks up a special method in the type's MRO without checking instance dict.
792 /// Returns None if not found (masking AttributeError like CPython).
793 pub fn lookup_special(&self, attr: &Py<PyStr>, vm: &VirtualMachine) -> Option<PyObjectRef> {
794 let obj_cls = self.class();
795
796 // Use PyType::lookup_ref (equivalent to CPython's _PyType_LookupRef)
797 let res = obj_cls.lookup_ref(attr, vm)?;
798
799 // If it's a descriptor, call its __get__ method
800 let descr_get = res.class().slots.descr_get.load();
801 if let Some(descr_get) = descr_get {
802 let obj_cls = obj_cls.to_owned().into();
803 // CPython ignores exceptions in _PyObject_LookupSpecial and returns NULL
804 descr_get(res, Some(self.to_owned()), Some(obj_cls), vm).ok()
805 } else {
806 Some(res)
807 }
808 }
809}

Callers 2

is_subclassMethod · 0.80

Calls 6

lookup_refMethod · 0.80
okMethod · 0.80
SomeClass · 0.50
classMethod · 0.45
loadMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected