From 293c7e00d5bf200c1c6e35d4b368ccbbd439b97e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 31 Jan 2023 12:41:22 -0500 Subject: [PATCH] Include method name in B027 message (#2403) --- .../flake8_bugbear/rules/abstract_base_class.rs | 17 ++++++++++------- ...es__flake8_bugbear__tests__B027_B027.py.snap | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/rules/flake8_bugbear/rules/abstract_base_class.rs b/src/rules/flake8_bugbear/rules/abstract_base_class.rs index ad422b7d8f..0245ecf178 100644 --- a/src/rules/flake8_bugbear/rules/abstract_base_class.rs +++ b/src/rules/flake8_bugbear/rules/abstract_base_class.rs @@ -62,16 +62,19 @@ pub fn abstract_base_class( continue; } - let (StmtKind::FunctionDef { + let ( + StmtKind::FunctionDef { decorator_list, body, + name: method_name, + .. + } | StmtKind::AsyncFunctionDef { + decorator_list, + body, + name: method_name, .. } - | StmtKind::AsyncFunctionDef { - decorator_list, - body, - .. - }) = &stmt.node else { + ) = &stmt.node else { continue; }; @@ -89,7 +92,7 @@ pub fn abstract_base_class( if !has_abstract_decorator && is_empty_body(body) && !is_overload(checker, decorator_list) { checker.diagnostics.push(Diagnostic::new( violations::EmptyMethodWithoutAbstractDecorator { - name: name.to_string(), + name: format!("{name}.{method_name}"), }, Range::from_located(stmt), )); diff --git a/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap b/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap index cd3001ced2..9ed1ae1f63 100644 --- a/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap +++ b/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap @@ -4,7 +4,7 @@ expression: diagnostics --- - kind: EmptyMethodWithoutAbstractDecorator: - name: AbstractClass + name: AbstractClass.empty_1 location: row: 13 column: 4 @@ -15,7 +15,7 @@ expression: diagnostics parent: ~ - kind: EmptyMethodWithoutAbstractDecorator: - name: AbstractClass + name: AbstractClass.empty_2 location: row: 16 column: 4 @@ -26,7 +26,7 @@ expression: diagnostics parent: ~ - kind: EmptyMethodWithoutAbstractDecorator: - name: AbstractClass + name: AbstractClass.empty_3 location: row: 19 column: 4 @@ -37,7 +37,7 @@ expression: diagnostics parent: ~ - kind: EmptyMethodWithoutAbstractDecorator: - name: AbstractClass + name: AbstractClass.empty_4 location: row: 23 column: 4