Skip to content

Commit

Permalink
Recode TRY302 to TRY203 (#13502)
Browse files Browse the repository at this point in the history
Closes #13492
  • Loading branch information
zanieb authored and AlexWaygood committed Oct 17, 2024
1 parent 9218d6b commit 70e5c4a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Tryceratops, "004") => (RuleGroup::Stable, rules::tryceratops::rules::TypeCheckWithoutTypeError),
(Tryceratops, "200") => (RuleGroup::Removed, rules::tryceratops::rules::ReraiseNoCause),
(Tryceratops, "201") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseRaise),
(Tryceratops, "203") => (RuleGroup::Stable, rules::tryceratops::rules::UselessTryExcept),
(Tryceratops, "300") => (RuleGroup::Stable, rules::tryceratops::rules::TryConsiderElse),
(Tryceratops, "301") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseWithinTry),
(Tryceratops, "302") => (RuleGroup::Stable, rules::tryceratops::rules::UselessTryExcept),
(Tryceratops, "400") => (RuleGroup::Stable, rules::tryceratops::rules::ErrorInsteadOfException),
(Tryceratops, "401") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseLogMessage),

Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/rule_redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("PLW0117", "PLW0177"),
// See: https://github.com/astral-sh/ruff/issues/12110
("RUF025", "C420"),
// See: https://github.com/astral-sh/ruff/issues/13492
("TRY302", "TRY203"),
])
});
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/tryceratops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ mod tests {
#[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"))]
#[test_case(Rule::TypeCheckWithoutTypeError, Path::new("TRY004.py"))]
#[test_case(Rule::VerboseRaise, Path::new("TRY201.py"))]
#[test_case(Rule::UselessTryExcept, Path::new("TRY203.py"))]
#[test_case(Rule::TryConsiderElse, Path::new("TRY300.py"))]
#[test_case(Rule::RaiseWithinTry, Path::new("TRY301.py"))]
#[test_case(Rule::UselessTryExcept, Path::new("TRY302.py"))]
#[test_case(Rule::ErrorInsteadOfException, Path::new("TRY400.py"))]
#[test_case(Rule::VerboseLogMessage, Path::new("TRY401.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Violation for UselessTryExcept {
}
}

/// TRY302
/// TRY203 (previously TRY302)
pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandler]) {
if let Some(diagnostics) = handlers
.iter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,150 +1,148 @@
---
source: crates/ruff_linter/src/rules/tryceratops/mod.rs
---
TRY302.py:12:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:12:5: TRY203 Remove exception handler; error is immediately re-raised
|
10 | try:
11 | process()
12 | except Exception:
| _____^
13 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
14 |
15 | def bad():
|

TRY302.py:18:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:18:5: TRY203 Remove exception handler; error is immediately re-raised
|
16 | try:
17 | process()
18 | except Exception:
| _____^
19 | | raise
20 | | print("this code is pointless!")
| |________________________________________^ TRY302
| |________________________________________^ TRY203
21 |
22 | def bad():
|

TRY302.py:25:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:25:5: TRY203 Remove exception handler; error is immediately re-raised
|
23 | try:
24 | process()
25 | except:
| _____^
26 | | # I am a comment, not a statement!
27 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
28 |
29 | def bad():
|

TRY302.py:32:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:32:5: TRY203 Remove exception handler; error is immediately re-raised
|
30 | try:
31 | process()
32 | except Exception:
| _____^
33 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
34 |
35 | def bad():
|

TRY302.py:38:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:38:5: TRY203 Remove exception handler; error is immediately re-raised
|
36 | try:
37 | process()
38 | except Exception as e:
| _____^
39 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
40 |
41 | def bad():
|

TRY302.py:44:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:44:5: TRY203 Remove exception handler; error is immediately re-raised
|
42 | try:
43 | process()
44 | except Exception as e:
| _____^
45 | | raise e
| |_______________^ TRY302
| |_______________^ TRY203
46 |
47 | def bad():
|

TRY302.py:50:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:50:5: TRY203 Remove exception handler; error is immediately re-raised
|
48 | try:
49 | process()
50 | except MyException:
| _____^
51 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
52 | except Exception:
53 | raise
|

TRY302.py:52:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:52:5: TRY203 Remove exception handler; error is immediately re-raised
|
50 | except MyException:
51 | raise
52 | except Exception:
| _____^
53 | | raise
| |_____________^ TRY302
| |_____________^ TRY203
54 |
55 | def bad():
|

TRY302.py:58:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:58:5: TRY203 Remove exception handler; error is immediately re-raised
|
56 | try:
57 | process()
58 | except MyException as e:
| _____^
59 | | raise e
| |_______________^ TRY302
| |_______________^ TRY203
60 | except Exception as e:
61 | raise e
|

TRY302.py:60:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:60:5: TRY203 Remove exception handler; error is immediately re-raised
|
58 | except MyException as e:
59 | raise e
60 | except Exception as e:
| _____^
61 | | raise e
| |_______________^ TRY302
| |_______________^ TRY203
62 |
63 | def bad():
|

TRY302.py:66:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:66:5: TRY203 Remove exception handler; error is immediately re-raised
|
64 | try:
65 | process()
66 | except MyException as ex:
| _____^
67 | | raise ex
| |________________^ TRY302
| |________________^ TRY203
68 | except Exception as e:
69 | raise e
|

TRY302.py:68:5: TRY302 Remove exception handler; error is immediately re-raised
TRY203.py:68:5: TRY203 Remove exception handler; error is immediately re-raised
|
66 | except MyException as ex:
67 | raise ex
68 | except Exception as e:
| _____^
69 | | raise e
| |_______________^ TRY302
| |_______________^ TRY203
70 |
71 | def fine():
|


2 changes: 1 addition & 1 deletion ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70e5c4a

Please sign in to comment.