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

Function subclasscheck_check_registry

crates/vm/src/stdlib/_abc.rs:287–318  ·  view source on GitHub ↗

Check if subclass is in registry (recursive)

(
        impl_data: &AbcData,
        subclass: &PyObject,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

285
286 /// Check if subclass is in registry (recursive)
287 fn subclasscheck_check_registry(
288 impl_data: &AbcData,
289 subclass: &PyObject,
290 vm: &VirtualMachine,
291 ) -> PyResult<Option<bool>> {
292 // Fast path: check if subclass is in weakref directly
293 if in_weak_set(&impl_data.registry, subclass, vm)? {
294 return Ok(Some(true));
295 }
296
297 let registry_opt = impl_data.registry.read();
298 let registry = match &*registry_opt {
299 Some(s) => s.clone(),
300 None => return Ok(None),
301 };
302 drop(registry_opt);
303
304 // Make a local copy to protect against concurrent modifications
305 let registry_copy = PyFrozenSet::from_iter(vm, registry.elements().into_iter())?;
306
307 for weak_ref_obj in registry_copy.elements() {
308 if let Ok(weak_ref) = weak_ref_obj.downcast::<PyWeak>()
309 && let Some(rkey) = weak_ref.upgrade()
310 && subclass.to_owned().is_subclass(&rkey, vm)?
311 {
312 add_to_weak_set(&impl_data.cache, subclass, vm)?;
313 return Ok(Some(true));
314 }
315 }
316
317 Ok(None)
318 }
319
320 /// Internal ABC helper for subclass checks. Should be never used outside abc module.
321 #[pyfunction]

Callers 1

_abc_subclasscheckFunction · 0.85

Calls 10

in_weak_setFunction · 0.85
add_to_weak_setFunction · 0.85
is_subclassMethod · 0.80
SomeClass · 0.50
readMethod · 0.45
cloneMethod · 0.45
into_iterMethod · 0.45
elementsMethod · 0.45
upgradeMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected