Use matches! for CallPath comparisons (#5099)

## Summary

This PR consistently uses `matches! for static `CallPath` comparisons.
In some cases, we can significantly reduce the number of cases or
checks.

## Test Plan

`cargo test `
This commit is contained in:
Charlie Marsh 2023-06-14 17:06:34 -04:00 committed by GitHub
parent bae183b823
commit 56476dfd61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 251 additions and 220 deletions

View file

@ -19,7 +19,7 @@ pub fn is_staticmethod(decorator_list: &[Decorator], semantic: &SemanticModel) -
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
call_path.as_slice() == ["", "staticmethod"]
matches!(call_path.as_slice(), ["", "staticmethod"])
})
})
}
@ -30,7 +30,7 @@ pub fn is_classmethod(decorator_list: &[Decorator], semantic: &SemanticModel) ->
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
call_path.as_slice() == ["", "classmethod"]
matches!(call_path.as_slice(), ["", "classmethod"])
})
})
}
@ -81,11 +81,12 @@ pub fn is_property(
semantic
.resolve_call_path(map_callable(&decorator.expression))
.map_or(false, |call_path| {
call_path.as_slice() == ["", "property"]
|| call_path.as_slice() == ["functools", "cached_property"]
|| extra_properties
.iter()
.any(|extra_property| extra_property.as_slice() == call_path.as_slice())
matches!(
call_path.as_slice(),
["", "property"] | ["functools", "cached_property"]
) || extra_properties
.iter()
.any(|extra_property| extra_property.as_slice() == call_path.as_slice())
})
})
}