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

Method check_class

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

Equivalent to CPython's check_class. Returns Ok(()) if cls is a valid class, Err with TypeError if not. Uses abstract_get_bases internally.

(&self, vm: &VirtualMachine, msg: F)

Source from the content-addressed store, hash-verified

413 // Equivalent to CPython's check_class. Returns Ok(()) if cls is a valid class,
414 // Err with TypeError if not. Uses abstract_get_bases internally.
415 fn check_class<F>(&self, vm: &VirtualMachine, msg: F) -> PyResult<()>
416 where
417 F: Fn() -> String,
418 {
419 let cls = self;
420 match cls.abstract_get_bases(vm)? {
421 Some(_bases) => Ok(()), // Has __bases__, it's a valid class
422 None => {
423 // No __bases__ or __bases__ is not a tuple
424 Err(vm.new_type_error(msg()))
425 }
426 }
427 }
428
429 /// abstract_get_bases() has logically 4 return states:
430 /// 1. getattr(cls, '__bases__') could raise an AttributeError

Callers 2

recursive_issubclassMethod · 0.80
object_isinstanceMethod · 0.80

Calls 2

abstract_get_basesMethod · 0.80
ErrClass · 0.50

Tested by

no test coverage detected