Replace .map_or(false, $closure) with .is_some_and(closure) (#6244)

**Summary**
[Option::is_some_and](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.is_some_and)
and
[Result::is_ok_and](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok_and)
are new methods is rust 1.70. I find them way more readable than
`.map_or(false, ...)`.

The changes are `s/.map_or(false,/.is_some_and(/g`, then manually
switching to `is_ok_and` where the value is a Result rather than an
Option.

**Test Plan** n/a^
This commit is contained in:
konsti 2023-08-01 19:29:42 +02:00 committed by GitHub
parent 2e1754e5fc
commit 1df7e9831b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
162 changed files with 344 additions and 476 deletions

View file

@ -18,9 +18,7 @@ pub fn is_staticmethod(decorator_list: &[Decorator], semantic: &SemanticModel) -
decorator_list.iter().any(|decorator| {
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
matches!(call_path.as_slice(), ["", "staticmethod"])
})
.is_some_and(|call_path| matches!(call_path.as_slice(), ["", "staticmethod"]))
})
}
@ -29,9 +27,7 @@ pub fn is_classmethod(decorator_list: &[Decorator], semantic: &SemanticModel) ->
decorator_list.iter().any(|decorator| {
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
matches!(call_path.as_slice(), ["", "classmethod"])
})
.is_some_and(|call_path| matches!(call_path.as_slice(), ["", "classmethod"]))
})
}
@ -54,7 +50,7 @@ pub fn is_abstract(decorator_list: &[Decorator], semantic: &SemanticModel) -> bo
decorator_list.iter().any(|decorator| {
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
.is_some_and(|call_path| {
matches!(
call_path.as_slice(),
[
@ -80,7 +76,7 @@ pub fn is_property(
decorator_list.iter().any(|decorator| {
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
.is_some_and(|call_path| {
matches!(
call_path.as_slice(),
["", "property"] | ["functools", "cached_property"]
@ -208,7 +204,7 @@ pub(crate) fn method_visibility(stmt: &Stmt) -> Visibility {
}) => {
// Is this a setter or deleter?
if decorator_list.iter().any(|decorator| {
collect_call_path(&decorator.expression).map_or(false, |call_path| {
collect_call_path(&decorator.expression).is_some_and(|call_path| {
call_path.as_slice() == [name, "setter"]
|| call_path.as_slice() == [name, "deleter"]
})