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

Method extend_pyclass

crates/vm/src/stdlib/posix.rs:2797–2816  ·  view source on GitHub ↗
(ctx: &crate::vm::Context, class: &'static Py<crate::builtins::PyType>)

Source from the content-addressed store, hash-verified

2795
2796 #[extend_class]
2797 fn extend_pyclass(ctx: &crate::vm::Context, class: &'static Py<crate::builtins::PyType>) {
2798 // Override __reduce__ to return (type, (sched_priority,))
2799 // instead of the generic structseq (type, ((sched_priority,),)).
2800 // The trait's extend_class checks contains_key before setting default.
2801 const SCHED_PARAM_REDUCE: crate::function::PyMethodDef =
2802 crate::function::PyMethodDef::new_const(
2803 "__reduce__",
2804 |zelf: crate::PyRef<crate::builtins::PyTuple>,
2805 vm: &VirtualMachine|
2806 -> PyTupleRef {
2807 vm.new_tuple((zelf.class().to_owned(), (zelf[0].clone(),)))
2808 },
2809 crate::function::PyMethodFlags::METHOD,
2810 None,
2811 );
2812 class.set_attr(
2813 ctx.intern_str("__reduce__"),
2814 SCHED_PARAM_REDUCE.to_proper_method(class, ctx),
2815 );
2816 }
2817 }
2818
2819 #[cfg(not(target_env = "musl"))]

Callers

nothing calls this directly

Calls 7

intern_strMethod · 0.80
to_proper_methodMethod · 0.80
new_tupleMethod · 0.45
to_ownedMethod · 0.45
classMethod · 0.45
cloneMethod · 0.45
set_attrMethod · 0.45

Tested by

no test coverage detected