[flake8-bugbear] Fix False Positives for B024 & B027 (#1851)

closes https://github.com/charliermarsh/ruff/issues/1848
This commit is contained in:
Maksudul Haque
2023-01-13 22:46:17 +06:00
committed by GitHub
parent 048e5774e8
commit 3ae01db226
5 changed files with 71 additions and 30 deletions

View File

@@ -52,6 +52,20 @@ fn is_abstractmethod(
match_module_member(expr, "abc", "abstractmethod", from_imports, import_aliases)
}
fn is_abstractproperty(
expr: &Expr,
from_imports: &FxHashMap<&str, FxHashSet<&str>>,
import_aliases: &FxHashMap<&str, &str>,
) -> bool {
match_module_member(
expr,
"abc",
"abstractproperty",
from_imports,
import_aliases,
)
}
fn is_overload(
expr: &Expr,
from_imports: &FxHashMap<&str, FxHashSet<&str>>,
@@ -102,9 +116,10 @@ pub fn abstract_base_class(
continue;
};
let has_abstract_decorator = decorator_list
.iter()
.any(|d| is_abstractmethod(d, &checker.from_imports, &checker.import_aliases));
let has_abstract_decorator = decorator_list.iter().any(|d| {
is_abstractmethod(d, &checker.from_imports, &checker.import_aliases)
|| is_abstractproperty(d, &checker.from_imports, &checker.import_aliases)
});
has_abstract_method |= has_abstract_decorator;

View File

@@ -1,64 +1,64 @@
---
source: src/flake8_bugbear/mod.rs
expression: checks
expression: diagnostics
---
- kind:
AbstractBaseClassWithoutAbstractMethod: Base_1
location:
row: 17
row: 18
column: 0
end_location:
row: 19
row: 20
column: 13
fix: ~
parent: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: MetaBase_1
location:
row: 58
row: 71
column: 0
end_location:
row: 60
row: 73
column: 13
fix: ~
parent: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_Base_1
location:
row: 69
row: 82
column: 0
end_location:
row: 71
row: 84
column: 13
fix: ~
parent: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_Base_2
location:
row: 74
row: 87
column: 0
end_location:
row: 76
row: 89
column: 13
fix: ~
parent: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: notabc_Base_1
location:
row: 79
row: 92
column: 0
end_location:
row: 81
row: 94
column: 13
fix: ~
parent: ~
- kind:
AbstractBaseClassWithoutAbstractMethod: abc_set_class_variable_4
location:
row: 128
row: 141
column: 0
end_location:
row: 129
row: 142
column: 7
fix: ~
parent: ~

View File

@@ -1,44 +1,44 @@
---
source: src/flake8_bugbear/mod.rs
expression: checks
expression: diagnostics
---
- kind:
EmptyMethodWithoutAbstractDecorator: AbstractClass
location:
row: 12
row: 13
column: 4
end_location:
row: 13
row: 14
column: 11
fix: ~
parent: ~
- kind:
EmptyMethodWithoutAbstractDecorator: AbstractClass
location:
row: 15
row: 16
column: 4
end_location:
row: 16
row: 17
column: 12
fix: ~
parent: ~
- kind:
EmptyMethodWithoutAbstractDecorator: AbstractClass
location:
row: 18
row: 19
column: 4
end_location:
row: 20
row: 21
column: 11
fix: ~
parent: ~
- kind:
EmptyMethodWithoutAbstractDecorator: AbstractClass
location:
row: 22
row: 23
column: 4
end_location:
row: 27
row: 28
column: 12
fix: ~
parent: ~