diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index bc3ca8ae2..c415aa1af 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -48,10 +48,8 @@ pub fn init(context: &PyContext) { fn to_op_complex(value: &PyObjectRef, vm: &VirtualMachine) -> PyResult> { let r = if let Some(complex) = value.payload_if_subclass::(vm) { Some(complex.value) - } else if let Some(float) = float::to_op_float(value, vm)? { - Some(Complex64::new(float, 0.0)) } else { - None + float::to_op_float(value, vm)?.map(|float| Complex64::new(float, 0.0)) }; Ok(r) } diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index 2e09b6811..c50ff3ffb 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -584,10 +584,10 @@ impl Iterator for DictIter { type Item = (PyObjectRef, PyObjectRef); fn next(&mut self) -> Option { - match self.dict.entries.next_entry(&mut self.position) { - Some((key, value)) => Some((key, value)), - None => None, - } + self.dict + .entries + .next_entry(&mut self.position) + .map(|(key, value)| (key, value)) } fn size_hint(&self) -> (usize, Option) { diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index f71a36543..b83acbc4d 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -449,15 +449,12 @@ impl PyBoundMethod { #[pymethod(magic)] fn repr(&self, vm: &VirtualMachine) -> PyResult { - let funcname = if let Some(qname) = - vm.get_attribute_opt(self.function.clone(), "__qualname__")? - { - Some(qname) - } else if let Some(name) = vm.get_attribute_opt(self.function.clone(), "__qualname__")? { - Some(name) - } else { - None - }; + let funcname = + if let Some(qname) = vm.get_attribute_opt(self.function.clone(), "__qualname__")? { + Some(qname) + } else { + vm.get_attribute_opt(self.function.clone(), "__qualname__")? + }; let funcname: Option = funcname.and_then(|o| o.downcast().ok()); Ok(format!( "", diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 321846f0d..e3bc4d522 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -439,10 +439,8 @@ impl ExecutingFrame<'_> { // variable is Some let thrower = if let Some(coro) = self.builtin_coro(coro) { Some(Either::A(coro)) - } else if let Some(meth) = vm.get_attribute_opt(coro.clone(), "throw")? { - Some(Either::B(meth)) } else { - None + vm.get_attribute_opt(coro.clone(), "throw")?.map(Either::B) }; if let Some(thrower) = thrower { let ret = match thrower { diff --git a/vm/src/function.rs b/vm/src/function.rs index bfef80c7c..1c9f5f05e 100644 --- a/vm/src/function.rs +++ b/vm/src/function.rs @@ -219,11 +219,10 @@ impl FuncArgs { } pub fn check_kwargs_empty(&self, vm: &VirtualMachine) -> Option { - if let Some(k) = self.kwargs.keys().next() { - Some(vm.new_type_error(format!("Unexpected keyword argument {}", k))) - } else { - None - } + self.kwargs + .keys() + .next() + .map(|k| vm.new_type_error(format!("Unexpected keyword argument {}", k))) } } diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index f10565112..77a3762b5 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -278,10 +278,9 @@ mod decl { times: OptionalArg, vm: &VirtualMachine, ) -> PyResult> { - let times = match times.into_option() { - Some(int) => Some(PyRwLock::new(int.borrow_value().clone())), - None => None, - }; + let times = times + .into_option() + .map(|int| PyRwLock::new(int.borrow_value().clone())); PyItertoolsRepeat { object, times }.into_ref_with_type(vm, cls) }