Skip to content

Commit 8d59874

Browse files
committed
Add int __pos__ method
1 parent 9364902 commit 8d59874

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

vm/src/obj/objint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ fn int_neg(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
287287
Ok(vm.ctx.new_int(-i))
288288
}
289289

290+
fn int_pos(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
291+
arg_check!(vm, args, required = [(i, Some(vm.ctx.int_type()))]);
292+
Ok(i.clone())
293+
}
294+
290295
fn int_pow(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
291296
arg_check!(
292297
vm,
@@ -391,6 +396,7 @@ pub fn init(context: &PyContext) {
391396
int_type.set_attr("__mul__", context.new_rustfunc(int_mul));
392397
int_type.set_attr("__neg__", context.new_rustfunc(int_neg));
393398
int_type.set_attr("__or__", context.new_rustfunc(int_or));
399+
int_type.set_attr("__pos__", context.new_rustfunc(int_pos));
394400
int_type.set_attr("__pow__", context.new_rustfunc(int_pow));
395401
int_type.set_attr("__repr__", context.new_rustfunc(int_repr));
396402
int_type.set_attr("__sub__", context.new_rustfunc(int_sub));

0 commit comments

Comments
 (0)