Make setting and retrieving pydocstyle settings less tedious (#12582)

This commit is contained in:
Alex Waygood 2024-07-31 10:39:33 +01:00 committed by GitHub
parent 138e70bd5c
commit 83b1c48a93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 146 additions and 134 deletions

View file

@ -63,11 +63,16 @@ pub fn is_abstract(decorator_list: &[Decorator], semantic: &SemanticModel) -> bo
/// Returns `true` if a function definition is a `@property`.
/// `extra_properties` can be used to check additional non-standard
/// `@property`-like decorators.
pub fn is_property(
pub fn is_property<'a, P, I>(
decorator_list: &[Decorator],
extra_properties: &[QualifiedName],
extra_properties: P,
semantic: &SemanticModel,
) -> bool {
) -> bool
where
P: IntoIterator<IntoIter = I>,
I: Iterator<Item = QualifiedName<'a>> + Clone,
{
let extra_properties = extra_properties.into_iter();
decorator_list.iter().any(|decorator| {
semantic
.resolve_qualified_name(map_callable(&decorator.expression))
@ -79,8 +84,8 @@ pub fn is_property(
| ["abc", "abstractproperty"]
| ["types", "DynamicClassAttribute"]
) || extra_properties
.iter()
.any(|extra_property| extra_property.segments() == qualified_name.segments())
.clone()
.any(|extra_property| extra_property == qualified_name)
})
})
}

View file

@ -151,11 +151,11 @@ impl<'a> Definition<'a> {
)
}
pub fn is_property(
&self,
extra_properties: &[QualifiedName],
semantic: &SemanticModel,
) -> bool {
pub fn is_property<P, I>(&self, extra_properties: P, semantic: &SemanticModel) -> bool
where
P: IntoIterator<IntoIter = I>,
I: Iterator<Item = QualifiedName<'a>> + Clone,
{
self.as_function_def()
.is_some_and(|StmtFunctionDef { decorator_list, .. }| {
is_property(decorator_list, extra_properties, semantic)