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)
| 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 | } |