(
cls: PyObjectRef,
subclass: PyObjectRef,
vm: &VirtualMachine,
)
| 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] |
no test coverage detected