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

Function _abc_register

crates/vm/src/stdlib/_abc.rs:214–242  ·  view source on GitHub ↗
(
        cls: PyObjectRef,
        subclass: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

212 /// Internal ABC helper for subclass registration. Should be never used outside abc module.
213 #[pyfunction]
214 fn _abc_register(
215 cls: PyObjectRef,
216 subclass: PyObjectRef,
217 vm: &VirtualMachine,
218 ) -> PyResult<PyObjectRef> {
219 // Type check
220 if !subclass.class().fast_issubclass(vm.ctx.types.type_type) {
221 return Err(vm.new_type_error("Can only register classes"));
222 }
223
224 // Check if already a subclass
225 if subclass.is_subclass(&cls, vm)? {
226 return Ok(subclass);
227 }
228
229 // Check for cycles
230 if cls.is_subclass(&subclass, vm)? {
231 return Err(vm.new_runtime_error("Refusing to create an inheritance cycle"));
232 }
233
234 // Add to registry
235 let impl_data = get_impl(&cls, vm)?;
236 add_to_weak_set(&impl_data.registry, &subclass, vm)?;
237
238 // Invalidate negative cache
239 increment_invalidation_counter();
240
241 Ok(subclass)
242 }
243
244 /// Internal ABC helper for instance checks. Should be never used outside abc module.
245 #[pyfunction]

Callers 1

registerMethod · 0.90

Calls 7

get_implFunction · 0.85
add_to_weak_setFunction · 0.85
fast_issubclassMethod · 0.80
is_subclassMethod · 0.80
ErrClass · 0.50
classMethod · 0.45

Tested by

no test coverage detected