mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
Use class name as range for B024
(#4647)
This commit is contained in:
parent
28a5e607b4
commit
c9b39e31fc
3 changed files with 40 additions and 31 deletions
|
@ -120,3 +120,11 @@ class AbstractClass(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def empty_1(self, foo: Union[str, int, list, float]):
|
def empty_1(self, foo: Union[str, int, list, float]):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Foo(ABC): # noqa: B024
|
||||||
|
...
|
||||||
|
|
|
@ -2,6 +2,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged, Stmt};
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
use ruff_python_ast::helpers::identifier_range;
|
||||||
use ruff_python_semantic::analyze::visibility::{is_abstract, is_overload};
|
use ruff_python_semantic::analyze::visibility::{is_abstract, is_overload};
|
||||||
use ruff_python_semantic::model::SemanticModel;
|
use ruff_python_semantic::model::SemanticModel;
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ pub(crate) fn abstract_base_class(
|
||||||
AbstractBaseClassWithoutAbstractMethod {
|
AbstractBaseClassWithoutAbstractMethod {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
},
|
},
|
||||||
stmt.range(),
|
identifier_range(stmt, checker.locator),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,52 @@
|
||||||
---
|
---
|
||||||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
|
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
|
||||||
---
|
---
|
||||||
B024.py:18:1: B024 `Base_1` is an abstract base class, but it has no abstract methods
|
B024.py:18:7: B024 `Base_1` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
18 | / class Base_1(ABC): # error
|
18 | class Base_1(ABC): # error
|
||||||
19 | | def method(self):
|
| ^^^^^^ B024
|
||||||
20 | | foo()
|
19 | def method(self):
|
||||||
| |_____________^ B024
|
20 | foo()
|
||||||
|
|
|
|
||||||
|
|
||||||
B024.py:71:1: B024 `MetaBase_1` is an abstract base class, but it has no abstract methods
|
B024.py:71:7: B024 `MetaBase_1` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
71 | / class MetaBase_1(metaclass=ABCMeta): # error
|
71 | class MetaBase_1(metaclass=ABCMeta): # error
|
||||||
72 | | def method(self):
|
| ^^^^^^^^^^ B024
|
||||||
73 | | foo()
|
72 | def method(self):
|
||||||
| |_____________^ B024
|
73 | foo()
|
||||||
|
|
|
|
||||||
|
|
||||||
B024.py:82:1: B024 `abc_Base_1` is an abstract base class, but it has no abstract methods
|
B024.py:82:7: B024 `abc_Base_1` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
82 | / class abc_Base_1(abc.ABC): # error
|
82 | class abc_Base_1(abc.ABC): # error
|
||||||
83 | | def method(self):
|
| ^^^^^^^^^^ B024
|
||||||
84 | | foo()
|
83 | def method(self):
|
||||||
| |_____________^ B024
|
84 | foo()
|
||||||
|
|
|
|
||||||
|
|
||||||
B024.py:87:1: B024 `abc_Base_2` is an abstract base class, but it has no abstract methods
|
B024.py:87:7: B024 `abc_Base_2` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
87 | / class abc_Base_2(metaclass=abc.ABCMeta): # error
|
87 | class abc_Base_2(metaclass=abc.ABCMeta): # error
|
||||||
88 | | def method(self):
|
| ^^^^^^^^^^ B024
|
||||||
89 | | foo()
|
88 | def method(self):
|
||||||
| |_____________^ B024
|
89 | foo()
|
||||||
|
|
|
|
||||||
|
|
||||||
B024.py:92:1: B024 `notabc_Base_1` is an abstract base class, but it has no abstract methods
|
B024.py:92:7: B024 `notabc_Base_1` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
92 | / class notabc_Base_1(notabc.ABC): # error
|
92 | class notabc_Base_1(notabc.ABC): # error
|
||||||
93 | | def method(self):
|
| ^^^^^^^^^^^^^ B024
|
||||||
94 | | foo()
|
93 | def method(self):
|
||||||
| |_____________^ B024
|
94 | foo()
|
||||||
|
|
|
|
||||||
|
|
||||||
B024.py:141:1: B024 `abc_set_class_variable_4` is an abstract base class, but it has no abstract methods
|
B024.py:141:7: B024 `abc_set_class_variable_4` is an abstract base class, but it has no abstract methods
|
||||||
|
|
|
|
||||||
141 | # this doesn't actually declare a class variable, it's just an expression
|
141 | # this doesn't actually declare a class variable, it's just an expression
|
||||||
142 | / class abc_set_class_variable_4(ABC): # error
|
142 | class abc_set_class_variable_4(ABC): # error
|
||||||
143 | | foo
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ B024
|
||||||
| |_______^ B024
|
143 | foo
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue