Remove `pylint::helpers::CmpOpExt` (#13189)

This commit is contained in:
Alex Waygood 2024-09-01 02:55:24 +01:00 committed by GitHub
parent bf620dcb38
commit d3b6e8f58b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 37 deletions

View File

@ -1,8 +1,6 @@
use std::fmt;
use ruff_python_ast as ast;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{visitor, Arguments, CmpOp, Expr, Stmt};
use ruff_python_ast::{visitor, Arguments, Expr, Stmt};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::{ScopeKind, SemanticModel};
use ruff_text_size::TextRange;
@ -57,34 +55,6 @@ pub(super) fn in_dunder_method(
true
}
/// A wrapper around [`CmpOp`] that implements `Display`.
#[derive(Debug)]
pub(super) struct CmpOpExt(CmpOp);
impl From<&CmpOp> for CmpOpExt {
fn from(cmp_op: &CmpOp) -> Self {
CmpOpExt(*cmp_op)
}
}
impl fmt::Display for CmpOpExt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let representation = match self.0 {
CmpOp::Eq => "==",
CmpOp::NotEq => "!=",
CmpOp::Lt => "<",
CmpOp::LtE => "<=",
CmpOp::Gt => ">",
CmpOp::GtE => ">=",
CmpOp::Is => "is",
CmpOp::IsNot => "is not",
CmpOp::In => "in",
CmpOp::NotIn => "not in",
};
write!(f, "{representation}")
}
}
/// Visitor to track reads from an iterable in a loop.
#[derive(Debug)]
pub(crate) struct SequenceIndexVisitor<'a> {

View File

@ -6,7 +6,6 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;
use crate::rules::pylint::helpers::CmpOpExt;
/// ## What it does
/// Checks for comparisons between constants.
@ -45,8 +44,7 @@ impl Violation for ComparisonOfConstant {
} = self;
format!(
"Two constants compared in a comparison, consider replacing `{left_constant} {} {right_constant}`",
CmpOpExt::from(op)
"Two constants compared in a comparison, consider replacing `{left_constant} {op} {right_constant}`",
)
}
}

View File

@ -7,7 +7,6 @@ use ruff_python_ast::{CmpOp, Expr};
use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;
use crate::rules::pylint::helpers::CmpOpExt;
/// ## What it does
/// Checks for operations that compare a name to itself.
@ -66,7 +65,7 @@ pub(crate) fn comparison_with_itself(
let actual = format!(
"{} {} {}",
checker.locator().slice(left),
CmpOpExt::from(op),
op,
checker.locator().slice(right)
);
checker.diagnostics.push(Diagnostic::new(
@ -114,7 +113,7 @@ pub(crate) fn comparison_with_itself(
let actual = format!(
"{} {} {}",
checker.locator().slice(left),
CmpOpExt::from(op),
op,
checker.locator().slice(right)
);
checker.diagnostics.push(Diagnostic::new(