mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Add method.__reduce__
This commit is contained in:
1 parent
78586f0275
commit
df6d442ca8
2 files changed
+20
No files matched your search
@@ -254,6 +254,15 @@ impl PyBuiltinMethod {
|
||||
self.class.name()
|
||||
)
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn reduce(
|
||||
&self,
|
||||
vm: &VirtualMachine,
|
||||
) -> (Option<PyObjectRef>, (Option<PyObjectRef>, PyStrRef)) {
|
||||
let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok();
|
||||
let classname = vm.builtins.get_attr(self.class.name().to_string(), vm).ok();
|
||||
(builtinfunc_getattr, (classname, self.value.name.clone()))
|
||||
}
|
||||
}
|
||||
impl Unconstructible for PyBuiltinMethod {}
|
||||
|
||||
|
||||
@@ -552,6 +552,17 @@ impl PyBoundMethod {
|
||||
))
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn reduce(
|
||||
&self,
|
||||
vm: &VirtualMachine,
|
||||
) -> (Option<PyObjectRef>, (PyObjectRef, Option<PyObjectRef>)) {
|
||||
let builtinfunc_getattr = vm.builtins.get_attr("getattr", vm).ok();
|
||||
let funcself = self.object.clone();
|
||||
let funcname = self.function.get_attr("__name__", vm).ok();
|
||||
(builtinfunc_getattr, (funcself, funcname))
|
||||
}
|
||||
|
||||
#[pygetset(magic)]
|
||||
fn doc(&self, vm: &VirtualMachine) -> PyResult {
|
||||
self.function.get_attr("__doc__", vm)
|
||||
|
||||
Reference in new issue
Block a user