Skip to content

Commit a578414

Browse files
committed
Redirect TRY200 to B904 (#9755)
Follow-up to #9754 and #9689. Alternative to #9714. Marks `TRY200` as removed and redirects to `B904` instead of marking as deprecated and suggesting `B904` instead.
1 parent 0d752e5 commit a578414

File tree

7 files changed

+5
-93
lines changed

7 files changed

+5
-93
lines changed

crates/ruff_linter/resources/test/fixtures/tryceratops/TRY200.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

crates/ruff_linter/src/checkers/ast/analyze/except_handler.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::checkers::ast::Checker;
55
use crate::registry::Rule;
66
use crate::rules::{
77
flake8_bandit, flake8_blind_except, flake8_bugbear, flake8_builtins, pycodestyle, pylint,
8-
tryceratops,
98
};
109

1110
/// Run lint rules over an [`ExceptHandler`] syntax node.
@@ -66,9 +65,6 @@ pub(crate) fn except_handler(except_handler: &ExceptHandler, checker: &mut Check
6665
if checker.enabled(Rule::ExceptWithNonExceptionClasses) {
6766
flake8_bugbear::rules::except_with_non_exception_classes(checker, except_handler);
6867
}
69-
if checker.enabled(Rule::ReraiseNoCause) {
70-
tryceratops::rules::reraise_no_cause(checker, body);
71-
}
7268
if checker.enabled(Rule::BinaryOpException) {
7369
pylint::rules::binary_op_exception(checker, except_handler);
7470
}

crates/ruff_linter/src/codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
847847
(Tryceratops, "002") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseVanillaClass),
848848
(Tryceratops, "003") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseVanillaArgs),
849849
(Tryceratops, "004") => (RuleGroup::Stable, rules::tryceratops::rules::TypeCheckWithoutTypeError),
850-
(Tryceratops, "200") => (RuleGroup::Deprecated, rules::tryceratops::rules::ReraiseNoCause),
850+
(Tryceratops, "200") => (RuleGroup::Removed, rules::tryceratops::rules::ReraiseNoCause),
851851
(Tryceratops, "201") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseRaise),
852852
(Tryceratops, "300") => (RuleGroup::Stable, rules::tryceratops::rules::TryConsiderElse),
853853
(Tryceratops, "301") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseWithinTry),

crates/ruff_linter/src/rule_redirects.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
100100
("T004", "FIX004"),
101101
("RUF011", "B035"),
102102
("TCH006", "TCH010"),
103+
("TRY200", "B904"),
103104
// Test redirect by exact code
104105
#[cfg(feature = "test-rules")]
105106
("RUF940", "RUF950"),

crates/ruff_linter/src/rules/tryceratops/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ mod tests {
1818
#[test_case(Rule::RaiseVanillaClass, Path::new("TRY002.py"))]
1919
#[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"))]
2020
#[test_case(Rule::TypeCheckWithoutTypeError, Path::new("TRY004.py"))]
21-
#[test_case(Rule::ReraiseNoCause, Path::new("TRY200.py"))]
2221
#[test_case(Rule::VerboseRaise, Path::new("TRY201.py"))]
2322
#[test_case(Rule::TryConsiderElse, Path::new("TRY300.py"))]
2423
#[test_case(Rule::RaiseWithinTry, Path::new("TRY301.py"))]

crates/ruff_linter/src/rules/tryceratops/rules/reraise_no_cause.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
use ruff_python_ast::{Expr, Stmt};
2-
3-
use ruff_diagnostics::{Diagnostic, Violation};
1+
use ruff_diagnostics::Violation;
42
use ruff_macros::{derive_message_formats, violation};
5-
use ruff_python_ast::helpers::RaiseStatementVisitor;
6-
use ruff_python_ast::statement_visitor::StatementVisitor;
7-
8-
use crate::checkers::ast::Checker;
93

10-
/// ## Deprecation
4+
/// ## Removed
115
/// This rule is identical to [B904] which should be used instead.
126
///
137
/// ## What it does
@@ -44,28 +38,10 @@ use crate::checkers::ast::Checker;
4438
#[violation]
4539
pub struct ReraiseNoCause;
4640

41+
/// TRY200
4742
impl Violation for ReraiseNoCause {
4843
#[derive_message_formats]
4944
fn message(&self) -> String {
5045
format!("Use `raise from` to specify exception cause")
5146
}
5247
}
53-
54-
/// TRY200
55-
pub(crate) fn reraise_no_cause(checker: &mut Checker, body: &[Stmt]) {
56-
let raises = {
57-
let mut visitor = RaiseStatementVisitor::default();
58-
visitor.visit_body(body);
59-
visitor.raises
60-
};
61-
62-
for (range, exc, cause) in raises {
63-
if cause.is_none() {
64-
if exc.is_some_and(Expr::is_call_expr) {
65-
checker
66-
.diagnostics
67-
.push(Diagnostic::new(ReraiseNoCause, range));
68-
}
69-
}
70-
}
71-
}

crates/ruff_linter/src/rules/tryceratops/snapshots/ruff_linter__rules__tryceratops__tests__reraise-no-cause_TRY200.py.snap

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)