diff --git a/compiler/src/symboltable.rs b/compiler/src/symboltable.rs index 44c6df905..8eaa0958d 100644 --- a/compiler/src/symboltable.rs +++ b/compiler/src/symboltable.rs @@ -1074,10 +1074,8 @@ impl SymbolTableBuilder { ) -> SymbolTableResult { // Evaluate eventual default parameters: self.scan_expressions(&args.defaults, ExpressionContext::Load)?; - for kw_default in &args.kw_defaults { - if let Some(expression) = kw_default { - self.scan_expression(&expression, ExpressionContext::Load)?; - } + for expression in args.kw_defaults.iter().flatten() { + self.scan_expression(&expression, ExpressionContext::Load)?; } // Annotations are scanned in outer scope: diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index ebfaa0a17..f5844f370 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -717,7 +717,7 @@ where } } - Ok(IndentationLevel { spaces, tabs }) + Ok(IndentationLevel { tabs, spaces }) } fn handle_indentations(&mut self) -> Result<(), LexicalError> { 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..9ea313282 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -584,10 +584,7 @@ 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) } 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/py_serde.rs b/vm/src/py_serde.rs index 3345d90e0..ae6c5b9a6 100644 --- a/vm/src/py_serde.rs +++ b/vm/src/py_serde.rs @@ -16,7 +16,7 @@ pub fn serialize( where S: serde::Serializer, { - PyObjectSerializer { vm, pyobject }.serialize(serializer) + PyObjectSerializer { pyobject, vm }.serialize(serializer) } #[inline] @@ -39,7 +39,7 @@ pub struct PyObjectSerializer<'s> { impl<'s> PyObjectSerializer<'s> { pub fn new(vm: &'s VirtualMachine, pyobject: &'s PyObjectRef) -> Self { - PyObjectSerializer { vm, pyobject } + PyObjectSerializer { pyobject, vm } } fn clone_with_object(&self, pyobject: &'s PyObjectRef) -> PyObjectSerializer { diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index c8049880e..c2d342093 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -143,10 +143,10 @@ impl PyContext { let context = PyContext { true_value, false_value, - not_implemented, none, empty_tuple, ellipsis, + not_implemented, types, exceptions, 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) } diff --git a/vm/src/stdlib/ssl.rs b/vm/src/stdlib/ssl.rs index 95272959e..cd1c0d486 100644 --- a/vm/src/stdlib/ssl.rs +++ b/vm/src/stdlib/ssl.rs @@ -911,6 +911,7 @@ fn cert_to_py(vm: &VirtualMachine, cert: &X509Ref, binary: bool) -> PyResult { )?; dict.set_item("notAfter", vm.ctx.new_str(cert.not_after().to_string()), vm)?; + #[allow(clippy::manual_map)] if let Some(names) = cert.subject_alt_names() { let san = names .iter()