Recode TRY302 to TRY203 (#13502)

Closes https://github.com/astral-sh/ruff/issues/13492
This commit is contained in:
Zanie Blue 2024-10-08 11:41:27 -05:00 committed by Alex Waygood
parent 9218d6bedc
commit 70e5c4a8ba
7 changed files with 30 additions and 30 deletions

View file

@ -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, "004") => (RuleGroup::Stable, rules::tryceratops::rules::TypeCheckWithoutTypeError),
(Tryceratops, "200") => (RuleGroup::Removed, rules::tryceratops::rules::ReraiseNoCause), (Tryceratops, "200") => (RuleGroup::Removed, rules::tryceratops::rules::ReraiseNoCause),
(Tryceratops, "201") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseRaise), (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, "300") => (RuleGroup::Stable, rules::tryceratops::rules::TryConsiderElse),
(Tryceratops, "301") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseWithinTry), (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, "400") => (RuleGroup::Stable, rules::tryceratops::rules::ErrorInsteadOfException),
(Tryceratops, "401") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseLogMessage), (Tryceratops, "401") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseLogMessage),

View file

@ -125,5 +125,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
("PLW0117", "PLW0177"), ("PLW0117", "PLW0177"),
// See: https://github.com/astral-sh/ruff/issues/12110 // See: https://github.com/astral-sh/ruff/issues/12110
("RUF025", "C420"), ("RUF025", "C420"),
// See: https://github.com/astral-sh/ruff/issues/13492
("TRY302", "TRY203"),
]) ])
}); });

View file

@ -19,9 +19,9 @@ mod tests {
#[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"))] #[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"))]
#[test_case(Rule::TypeCheckWithoutTypeError, Path::new("TRY004.py"))] #[test_case(Rule::TypeCheckWithoutTypeError, Path::new("TRY004.py"))]
#[test_case(Rule::VerboseRaise, Path::new("TRY201.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::TryConsiderElse, Path::new("TRY300.py"))]
#[test_case(Rule::RaiseWithinTry, Path::new("TRY301.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::ErrorInsteadOfException, Path::new("TRY400.py"))]
#[test_case(Rule::VerboseLogMessage, Path::new("TRY401.py"))] #[test_case(Rule::VerboseLogMessage, Path::new("TRY401.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> { fn rules(rule_code: Rule, path: &Path) -> Result<()> {

View file

@ -38,7 +38,7 @@ impl Violation for UselessTryExcept {
} }
} }
/// TRY302 /// TRY203 (previously TRY302)
pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandler]) { pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandler]) {
if let Some(diagnostics) = handlers if let Some(diagnostics) = handlers
.iter() .iter()

View file

@ -1,19 +1,19 @@
--- ---
source: crates/ruff_linter/src/rules/tryceratops/mod.rs 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: 10 | try:
11 | process() 11 | process()
12 | except Exception: 12 | except Exception:
| _____^ | _____^
13 | | raise 13 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
14 | 14 |
15 | def bad(): 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: 16 | try:
17 | process() 17 | process()
@ -21,12 +21,12 @@ TRY302.py:18:5: TRY302 Remove exception handler; error is immediately re-raised
| _____^ | _____^
19 | | raise 19 | | raise
20 | | print("this code is pointless!") 20 | | print("this code is pointless!")
| |________________________________________^ TRY302 | |________________________________________^ TRY203
21 | 21 |
22 | def bad(): 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: 23 | try:
24 | process() 24 | process()
@ -34,117 +34,115 @@ TRY302.py:25:5: TRY302 Remove exception handler; error is immediately re-raised
| _____^ | _____^
26 | | # I am a comment, not a statement! 26 | | # I am a comment, not a statement!
27 | | raise 27 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
28 | 28 |
29 | def bad(): 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: 30 | try:
31 | process() 31 | process()
32 | except Exception: 32 | except Exception:
| _____^ | _____^
33 | | raise 33 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
34 | 34 |
35 | def bad(): 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: 36 | try:
37 | process() 37 | process()
38 | except Exception as e: 38 | except Exception as e:
| _____^ | _____^
39 | | raise 39 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
40 | 40 |
41 | def bad(): 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: 42 | try:
43 | process() 43 | process()
44 | except Exception as e: 44 | except Exception as e:
| _____^ | _____^
45 | | raise e 45 | | raise e
| |_______________^ TRY302 | |_______________^ TRY203
46 | 46 |
47 | def bad(): 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: 48 | try:
49 | process() 49 | process()
50 | except MyException: 50 | except MyException:
| _____^ | _____^
51 | | raise 51 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
52 | except Exception: 52 | except Exception:
53 | raise 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: 50 | except MyException:
51 | raise 51 | raise
52 | except Exception: 52 | except Exception:
| _____^ | _____^
53 | | raise 53 | | raise
| |_____________^ TRY302 | |_____________^ TRY203
54 | 54 |
55 | def bad(): 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: 56 | try:
57 | process() 57 | process()
58 | except MyException as e: 58 | except MyException as e:
| _____^ | _____^
59 | | raise e 59 | | raise e
| |_______________^ TRY302 | |_______________^ TRY203
60 | except Exception as e: 60 | except Exception as e:
61 | raise 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: 58 | except MyException as e:
59 | raise e 59 | raise e
60 | except Exception as e: 60 | except Exception as e:
| _____^ | _____^
61 | | raise e 61 | | raise e
| |_______________^ TRY302 | |_______________^ TRY203
62 | 62 |
63 | def bad(): 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: 64 | try:
65 | process() 65 | process()
66 | except MyException as ex: 66 | except MyException as ex:
| _____^ | _____^
67 | | raise ex 67 | | raise ex
| |________________^ TRY302 | |________________^ TRY203
68 | except Exception as e: 68 | except Exception as e:
69 | raise 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: 66 | except MyException as ex:
67 | raise ex 67 | raise ex
68 | except Exception as e: 68 | except Exception as e:
| _____^ | _____^
69 | | raise e 69 | | raise e
| |_______________^ TRY302 | |_______________^ TRY203
70 | 70 |
71 | def fine(): 71 | def fine():
| |

2
ruff.schema.json generated
View file

@ -4009,11 +4009,11 @@
"TRY2", "TRY2",
"TRY20", "TRY20",
"TRY201", "TRY201",
"TRY203",
"TRY3", "TRY3",
"TRY30", "TRY30",
"TRY300", "TRY300",
"TRY301", "TRY301",
"TRY302",
"TRY4", "TRY4",
"TRY40", "TRY40",
"TRY400", "TRY400",