Skip to content

Commit b725ca7

Browse files
morealclaude
andcommitted
Fix PyBoundMethod __reduce__ to propagate errors
Previously swallowed errors from get_attr with .ok(), silently returning None. Now propagates errors matching CPython's method_reduce. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a3fd9f commit b725ca7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/vm/src/builtins/function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,11 @@ impl PyBoundMethod {
12911291
fn __reduce__(
12921292
&self,
12931293
vm: &VirtualMachine,
1294-
) -> (Option<PyObjectRef>, (PyObjectRef, Option<PyObjectRef>)) {
1295-
let builtins_getattr = vm.builtins.get_attr("getattr", vm).ok();
1294+
) -> PyResult<(PyObjectRef, (PyObjectRef, PyObjectRef))> {
1295+
let builtins_getattr = vm.builtins.get_attr("getattr", vm)?;
12961296
let func_self = self.object.clone();
1297-
let func_name = self.function.get_attr("__name__", vm).ok();
1298-
(builtins_getattr, (func_self, func_name))
1297+
let func_name = self.function.get_attr("__name__", vm)?;
1298+
Ok((builtins_getattr, (func_self, func_name)))
12991299
}
13001300

13011301
#[pygetset]

0 commit comments

Comments
 (0)