Skip to content

Commit 08b716f

Browse files
Merge pull request RustPython#898 from youknowone/builtins-divmod
Fix __builtins__.divmod to reflect __rdivmod__
2 parents eb5cef2 + 14dd85a commit 08b716f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

vm/src/builtins.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ fn builtin_dir(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
123123
}
124124

125125
fn builtin_divmod(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
126-
arg_check!(vm, args, required = [(x, None), (y, None)]);
127-
match vm.get_method(x.clone(), "__divmod__") {
128-
Ok(attrib) => vm.invoke(attrib, vec![y.clone()]),
129-
Err(..) => Err(vm.new_type_error("unsupported operand type(s) for divmod".to_string())),
130-
}
126+
arg_check!(vm, args, required = [(a, None), (b, None)]);
127+
vm.call_or_reflection(
128+
a.clone(),
129+
b.clone(),
130+
"__divmod__",
131+
"__rdivmod__",
132+
|vm, a, b| Err(vm.new_unsupported_operand_error(a, b, "divmod")),
133+
)
131134
}
132135

133136
/// Implements `eval`.

0 commit comments

Comments
 (0)