mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:19 +00:00
Improve consistency between linter rules in determining whether a function is property (#12581)
This commit is contained in:
parent
264cd750e9
commit
4738135801
6 changed files with 67 additions and 28 deletions
|
@ -6,13 +6,16 @@ use std::ops::Deref;
|
|||
use std::path::Path;
|
||||
|
||||
use ruff_index::{newtype_index, IndexSlice, IndexVec};
|
||||
use ruff_python_ast::{self as ast, Stmt};
|
||||
use ruff_python_ast::name::QualifiedName;
|
||||
use ruff_python_ast::{self as ast, Stmt, StmtFunctionDef};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::analyze::visibility::{
|
||||
class_visibility, function_visibility, method_visibility, module_visibility, Visibility,
|
||||
class_visibility, function_visibility, is_property, method_visibility, module_visibility,
|
||||
Visibility,
|
||||
};
|
||||
use crate::model::all::DunderAllName;
|
||||
use crate::SemanticModel;
|
||||
|
||||
/// Id uniquely identifying a definition in a program.
|
||||
#[newtype_index]
|
||||
|
@ -148,6 +151,17 @@ impl<'a> Definition<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn is_property(
|
||||
&self,
|
||||
extra_properties: &[QualifiedName],
|
||||
semantic: &SemanticModel,
|
||||
) -> bool {
|
||||
self.as_function_def()
|
||||
.is_some_and(|StmtFunctionDef { decorator_list, .. }| {
|
||||
is_property(decorator_list, extra_properties, semantic)
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the name of the definition.
|
||||
pub fn name(&self) -> Option<&'a str> {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue