mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Include static and class methods in in abstract decorator list (#4298)
This commit is contained in:
parent
f23851130a
commit
d365dab904
3 changed files with 108 additions and 79 deletions
|
@ -60,13 +60,21 @@ pub fn is_override(ctx: &Context, decorator_list: &[Expr]) -> bool {
|
|||
.any(|expr| ctx.match_typing_expr(map_callable(expr), "override"))
|
||||
}
|
||||
|
||||
/// Returns `true` if a function definition is an `@abstractmethod`.
|
||||
/// Returns `true` if a function definition is an abstract method based on its decorators.
|
||||
pub fn is_abstract(ctx: &Context, decorator_list: &[Expr]) -> bool {
|
||||
decorator_list.iter().any(|expr| {
|
||||
ctx.resolve_call_path(map_callable(expr))
|
||||
.map_or(false, |call_path| {
|
||||
call_path.as_slice() == ["abc", "abstractmethod"]
|
||||
|| call_path.as_slice() == ["abc", "abstractproperty"]
|
||||
matches!(
|
||||
call_path.as_slice(),
|
||||
[
|
||||
"abc",
|
||||
"abstractmethod"
|
||||
| "abstractclassmethod"
|
||||
| "abstractstaticmethod"
|
||||
| "abstractproperty"
|
||||
]
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue