From a4a6e8dabe2603cfbc7d3cea7b83c3518b04a4f3 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 6 Apr 2023 00:32:47 +0900 Subject: [PATCH] Fix trivial suggestions --- vm/src/builtins/float.rs | 3 +-- vm/src/stdlib/builtins.rs | 6 ++---- vm/src/types/slot.rs | 26 ++++++++++---------------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index 952f7489e..00bf5e2c1 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -554,8 +554,7 @@ impl AsNumber for PyFloat { PyFloat::number_op(a, b, float_pow, vm) } else { Err(vm.new_type_error(String::from( - "pow() 3rd argument not \\ - allowed unless all arguments are integers", + "pow() 3rd argument not allowed unless all arguments are integers", ))) } }), diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index 02584c862..8a4d11298 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -621,10 +621,8 @@ mod builtins { exp: y, modulus, } = args; - match modulus { - None => vm._pow(&x, &y, vm.ctx.none.as_object()), - Some(z) => vm._pow(&x, &y, &z), - } + let modulus = modulus.as_ref().map_or(vm.ctx.none.as_object(), |m| m); + vm._pow(&x, &y, modulus) } #[pyfunction] diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index d7d301c60..b06db403d 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -567,28 +567,22 @@ impl PyType { } _ if name == identifier!(ctx, __pow__) => { toggle_subslot!(as_number, power, |a, b, c, vm| { - if vm.is_none(c) { - vm.call_special_method(a, identifier!(vm, __pow__), (b.to_owned(),)) + let args = if vm.is_none(c) { + vec![b.to_owned()] } else { - vm.call_special_method( - a, - identifier!(vm, __pow__), - (b.to_owned(), c.to_owned()), - ) - } + vec![b.to_owned(), c.to_owned()] + }; + vm.call_special_method(a, identifier!(vm, __pow__), args) }); } _ if name == identifier!(ctx, __rpow__) => { toggle_subslot!(as_number, right_power, |a, b, c, vm| { - if vm.is_none(c) { - vm.call_special_method(b, identifier!(vm, __rpow__), (a.to_owned(),)) + let args = if vm.is_none(c) { + vec![a.to_owned()] } else { - vm.call_special_method( - b, - identifier!(vm, __rpow__), - (a.to_owned(), c.to_owned()), - ) - } + vec![a.to_owned(), c.to_owned()] + }; + vm.call_special_method(b, identifier!(vm, __rpow__), args) }); } _ if name == identifier!(ctx, __ipow__) => {