Skip to content

Commit df6d442

Browse files
committed
Add method.__reduce__
1 parent 78586f0 commit df6d442

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

vm/src/builtins/builtinfunc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ impl PyBuiltinMethod {
254254
self.class.name()
255255
)
256256
}
257+
#[pymethod(magic)]
258+
fn reduce(
259+
&self,
260+
vm: &VirtualMachine,
261+
) -> (Option<PyObjectRef>, (Option<PyObjectRef>, PyStrRef)) {
262+
let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok();
263+
let classname = vm.builtins.get_attr(self.class.name().to_string(), vm).ok();
264+
(builtinfunc_getattr, (classname, self.value.name.clone()))
265+
}
257266
}
258267
impl Unconstructible for PyBuiltinMethod {}
259268

vm/src/builtins/function.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,17 @@ impl PyBoundMethod {
552552
))
553553
}
554554

555+
#[pymethod(magic)]
556+
fn reduce(
557+
&self,
558+
vm: &VirtualMachine,
559+
) -> (Option<PyObjectRef>, (PyObjectRef, Option<PyObjectRef>)) {
560+
let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok();
561+
let funcself = self.object.clone();
562+
let funcname = self.function.get_attr("__name__", vm).ok();
563+
(builtinfunc_getattr, (funcself, funcname))
564+
}
565+
555566
#[pygetset(magic)]
556567
fn doc(&self, vm: &VirtualMachine) -> PyResult {
557568
self.function.get_attr("__doc__", vm)

0 commit comments

Comments
 (0)