Use function range for reimplemented-operator diagnostics (#11271)

This commit is contained in:
Charlie Marsh
2024-05-03 16:11:02 -04:00
committed by GitHub
parent 894cd13ec1
commit 8dd38110d9
2 changed files with 10 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ use anyhow::Result;
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::identifier::Identifier;
use ruff_python_ast::{self as ast, Expr, ExprSlice, ExprSubscript, ExprTuple, Parameters, Stmt};
use ruff_python_semantic::SemanticModel;
use ruff_source_file::Locator;
@@ -118,7 +119,7 @@ impl Ranged for FunctionLike<'_> {
fn range(&self) -> TextRange {
match self {
Self::Lambda(expr) => expr.range(),
Self::Function(stmt) => stmt.range(),
Self::Function(stmt) => stmt.identifier(),
}
}
}

View File

@@ -778,18 +778,18 @@ FURB118.py:33:17: FURB118 [*] Use `operator.itemgetter(slice(None))` instead of
35 36 |
36 37 | def op_not2(x):
FURB118.py:36:1: FURB118 Use `operator.not_` instead of defining a function
FURB118.py:36:5: FURB118 Use `operator.not_` instead of defining a function
|
36 | / def op_not2(x):
37 | | return not x
| |________________^ FURB118
36 | def op_not2(x):
| ^^^^^^^ FURB118
37 | return not x
|
= help: Replace with `operator.not_`
FURB118.py:40:1: FURB118 Use `operator.add` instead of defining a function
FURB118.py:40:5: FURB118 Use `operator.add` instead of defining a function
|
40 | / def op_add2(x, y):
41 | | return x + y
| |________________^ FURB118
40 | def op_add2(x, y):
| ^^^^^^^ FURB118
41 | return x + y
|
= help: Replace with `operator.add`