diff --git a/src/ast/helpers.rs b/src/ast/helpers.rs index 856d2e4f07..b872e7064c 100644 --- a/src/ast/helpers.rs +++ b/src/ast/helpers.rs @@ -121,10 +121,9 @@ pub fn match_call_path( // `Match`). if num_segments == 0 { module.is_empty() - || from_imports - .get(module) - .map(|imports| imports.contains(member) || imports.contains("*")) - .unwrap_or(false) + || from_imports.get(module).map_or(false, |imports| { + imports.contains(member) || imports.contains("*") + }) } else { let components: Vec<&str> = module.split('.').collect(); @@ -148,8 +147,7 @@ pub fn match_call_path( let member = components[cut]; if from_imports .get(&module.as_str()) - .map(|imports| imports.contains(member)) - .unwrap_or(false) + .map_or(false, |imports| imports.contains(member)) { return true; } diff --git a/src/check_ast.rs b/src/check_ast.rs index c4c987e324..6efaa41d8a 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -603,8 +603,7 @@ where .node .asname .as_ref() - .map(|asname| asname == &alias.node.name) - .unwrap_or(false) + .map_or(false, |asname| asname == &alias.node.name) { Some(( self.scopes[*(self @@ -823,8 +822,7 @@ where .node .asname .as_ref() - .map(|asname| asname == &alias.node.name) - .unwrap_or(false) + .map_or(false, |asname| asname == &alias.node.name) { Some(( self.scopes[*(self @@ -2341,8 +2339,7 @@ impl<'a> Checker<'a> { .current_scope() .values .get(id) - .map(|binding| matches!(binding.kind, BindingKind::Global)) - .unwrap_or(false) + .map_or(false, |binding| matches!(binding.kind, BindingKind::Global)) { pep8_naming::plugins::non_lowercase_variable_in_function(self, expr, parent, id) } diff --git a/src/flake8_bugbear/plugins/abstract_base_class.rs b/src/flake8_bugbear/plugins/abstract_base_class.rs index f37ab80a9a..118d4fe5df 100644 --- a/src/flake8_bugbear/plugins/abstract_base_class.rs +++ b/src/flake8_bugbear/plugins/abstract_base_class.rs @@ -17,8 +17,7 @@ fn is_abc_class( .node .arg .as_ref() - .map(|a| a == "metaclass") - .unwrap_or(false) + .map_or(false, |a| a == "metaclass") && match_module_member( &keyword.node.value, "abc", diff --git a/src/isort/categorize.rs b/src/isort/categorize.rs index 5e26cbca8e..d246579fba 100644 --- a/src/isort/categorize.rs +++ b/src/isort/categorize.rs @@ -21,7 +21,7 @@ pub fn categorize( known_third_party: &BTreeSet, extra_standard_library: &BTreeSet, ) -> ImportType { - if level.map(|level| *level > 0).unwrap_or(false) { + if level.map_or(false, |level| *level > 0) { ImportType::LocalFolder } else if known_first_party.contains(module_base) { ImportType::FirstParty diff --git a/src/isort/sorting.rs b/src/isort/sorting.rs index 2092019d39..365d4f671c 100644 --- a/src/isort/sorting.rs +++ b/src/isort/sorting.rs @@ -26,8 +26,7 @@ pub fn member_key<'a>( } else if name .chars() .next() - .map(|char| char.is_uppercase()) - .unwrap_or(false) + .map_or(false, |char| char.is_uppercase()) { // Ex) `Class` Prefix::Classes diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/checks.rs index f819615d73..e810ce207f 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/checks.rs @@ -11,13 +11,7 @@ use crate::python::string::{self}; /// N801 pub fn invalid_class_name(class_def: &Stmt, name: &str) -> Option { let stripped = name.strip_prefix('_').unwrap_or(name); - if !stripped - .chars() - .next() - .map(|c| c.is_uppercase()) - .unwrap_or(false) - || stripped.contains('_') - { + if !stripped.chars().next().map_or(false, |c| c.is_uppercase()) || stripped.contains('_') { return Some(Check::new( CheckKind::InvalidClassName(name.to_string()), Range::from_located(class_def), diff --git a/src/pydocstyle/plugins.rs b/src/pydocstyle/plugins.rs index f9e1164394..919c97cdad 100644 --- a/src/pydocstyle/plugins.rs +++ b/src/pydocstyle/plugins.rs @@ -1224,8 +1224,7 @@ fn common_section( if context .following_lines .last() - .map(|line| !line.trim().is_empty()) - .unwrap_or(true) + .map_or(true, |line| !line.trim().is_empty()) { if context.is_last_section { if checker.settings.enabled.contains(&CheckCode::D413) { @@ -1366,8 +1365,7 @@ fn args_section(checker: &mut Checker, definition: &Definition, context: &Sectio if line .chars() .next() - .map(|char| char.is_whitespace()) - .unwrap_or(true) + .map_or(true, |char| char.is_whitespace()) { // This is a continuation of documentation for the last // parameter because it does start with whitespace. diff --git a/src/settings/configuration.rs b/src/settings/configuration.rs index 78522d7df3..6cdf1fdfd6 100644 --- a/src/settings/configuration.rs +++ b/src/settings/configuration.rs @@ -83,9 +83,14 @@ impl Configuration { .map_err(|e| anyhow!("Invalid dummy-variable-rgx value: {e}"))?, None => DEFAULT_DUMMY_VARIABLE_RGX.clone(), }, - src: options - .src - .map(|src| { + src: options.src.map_or_else( + || { + vec![match project_root { + Some(project_root) => project_root.clone(), + None => path_dedot::CWD.clone(), + }] + }, + |src| { src.iter() .map(|path| { let path = Path::new(path); @@ -95,13 +100,8 @@ impl Configuration { } }) .collect() - }) - .unwrap_or_else(|| { - vec![match project_root { - Some(project_root) => project_root.clone(), - None => path_dedot::CWD.clone(), - }] - }), + }, + ), target_version: options.target_version.unwrap_or(PythonVersion::Py310), exclude: options .exclude