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

Function is_getstate_overridden

crates/vm/src/builtins/object.rs:640–657  ·  view source on GitHub ↗

Check if __getstate__ is overridden by comparing with object.__getstate__

(obj: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

638
639/// Check if __getstate__ is overridden by comparing with object.__getstate__
640fn is_getstate_overridden(obj: &PyObject, vm: &VirtualMachine) -> bool {
641 let obj_cls = obj.class();
642 let object_type = vm.ctx.types.object_type;
643
644 // If the class is object itself, not overridden
645 if obj_cls.is(object_type) {
646 return false;
647 }
648
649 // Check if __getstate__ in the MRO comes from object or elsewhere
650 // If the type has its own __getstate__, it's overridden
651 if let Some(getstate) = obj_cls.get_attr(identifier!(vm, __getstate__))
652 && let Some(obj_getstate) = object_type.get_attr(identifier!(vm, __getstate__))
653 {
654 return !getstate.is(&obj_getstate);
655 }
656 false
657}
658
659/// object_getstate - calls __getstate__ method or default implementation
660fn object_getstate(obj: &PyObject, required: bool, vm: &VirtualMachine) -> PyResult {

Callers 1

object_getstateFunction · 0.85

Calls 3

isMethod · 0.80
classMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected