Include method name in B027 message (#2403)

This commit is contained in:
Charlie Marsh 2023-01-31 12:41:22 -05:00 committed by GitHub
parent c3a3195922
commit 293c7e00d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -62,16 +62,19 @@ pub fn abstract_base_class(
continue; continue;
} }
let (StmtKind::FunctionDef { let (
StmtKind::FunctionDef {
decorator_list, decorator_list,
body, body,
name: method_name,
..
} | StmtKind::AsyncFunctionDef {
decorator_list,
body,
name: method_name,
.. ..
} }
| StmtKind::AsyncFunctionDef { ) = &stmt.node else {
decorator_list,
body,
..
}) = &stmt.node else {
continue; continue;
}; };
@ -89,7 +92,7 @@ pub fn abstract_base_class(
if !has_abstract_decorator && is_empty_body(body) && !is_overload(checker, decorator_list) { if !has_abstract_decorator && is_empty_body(body) && !is_overload(checker, decorator_list) {
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
violations::EmptyMethodWithoutAbstractDecorator { violations::EmptyMethodWithoutAbstractDecorator {
name: name.to_string(), name: format!("{name}.{method_name}"),
}, },
Range::from_located(stmt), Range::from_located(stmt),
)); ));

View File

@ -4,7 +4,7 @@ expression: diagnostics
--- ---
- kind: - kind:
EmptyMethodWithoutAbstractDecorator: EmptyMethodWithoutAbstractDecorator:
name: AbstractClass name: AbstractClass.empty_1
location: location:
row: 13 row: 13
column: 4 column: 4
@ -15,7 +15,7 @@ expression: diagnostics
parent: ~ parent: ~
- kind: - kind:
EmptyMethodWithoutAbstractDecorator: EmptyMethodWithoutAbstractDecorator:
name: AbstractClass name: AbstractClass.empty_2
location: location:
row: 16 row: 16
column: 4 column: 4
@ -26,7 +26,7 @@ expression: diagnostics
parent: ~ parent: ~
- kind: - kind:
EmptyMethodWithoutAbstractDecorator: EmptyMethodWithoutAbstractDecorator:
name: AbstractClass name: AbstractClass.empty_3
location: location:
row: 19 row: 19
column: 4 column: 4
@ -37,7 +37,7 @@ expression: diagnostics
parent: ~ parent: ~
- kind: - kind:
EmptyMethodWithoutAbstractDecorator: EmptyMethodWithoutAbstractDecorator:
name: AbstractClass name: AbstractClass.empty_4
location: location:
row: 23 row: 23
column: 4 column: 4