Skip to content

Commit 70e5c4a

Browse files
zaniebAlexWaygood
authored andcommitted
Recode TRY302 to TRY203 (#13502)
Closes #13492
1 parent 9218d6b commit 70e5c4a

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

crates/ruff_linter/src/codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
855855
(Tryceratops, "004") => (RuleGroup::Stable, rules::tryceratops::rules::TypeCheckWithoutTypeError),
856856
(Tryceratops, "200") => (RuleGroup::Removed, rules::tryceratops::rules::ReraiseNoCause),
857857
(Tryceratops, "201") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseRaise),
858+
(Tryceratops, "203") => (RuleGroup::Stable, rules::tryceratops::rules::UselessTryExcept),
858859
(Tryceratops, "300") => (RuleGroup::Stable, rules::tryceratops::rules::TryConsiderElse),
859860
(Tryceratops, "301") => (RuleGroup::Stable, rules::tryceratops::rules::RaiseWithinTry),
860-
(Tryceratops, "302") => (RuleGroup::Stable, rules::tryceratops::rules::UselessTryExcept),
861861
(Tryceratops, "400") => (RuleGroup::Stable, rules::tryceratops::rules::ErrorInsteadOfException),
862862
(Tryceratops, "401") => (RuleGroup::Stable, rules::tryceratops::rules::VerboseLogMessage),
863863

crates/ruff_linter/src/rule_redirects.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,7 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
125125
("PLW0117", "PLW0177"),
126126
// See: https://github.com/astral-sh/ruff/issues/12110
127127
("RUF025", "C420"),
128+
// See: https://github.com/astral-sh/ruff/issues/13492
129+
("TRY302", "TRY203"),
128130
])
129131
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ mod tests {
1919
#[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"))]
2020
#[test_case(Rule::TypeCheckWithoutTypeError, Path::new("TRY004.py"))]
2121
#[test_case(Rule::VerboseRaise, Path::new("TRY201.py"))]
22+
#[test_case(Rule::UselessTryExcept, Path::new("TRY203.py"))]
2223
#[test_case(Rule::TryConsiderElse, Path::new("TRY300.py"))]
2324
#[test_case(Rule::RaiseWithinTry, Path::new("TRY301.py"))]
24-
#[test_case(Rule::UselessTryExcept, Path::new("TRY302.py"))]
2525
#[test_case(Rule::ErrorInsteadOfException, Path::new("TRY400.py"))]
2626
#[test_case(Rule::VerboseLogMessage, Path::new("TRY401.py"))]
2727
fn rules(rule_code: Rule, path: &Path) -> Result<()> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Violation for UselessTryExcept {
3838
}
3939
}
4040

41-
/// TRY302
41+
/// TRY203 (previously TRY302)
4242
pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[ExceptHandler]) {
4343
if let Some(diagnostics) = handlers
4444
.iter()
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,148 @@
11
---
22
source: crates/ruff_linter/src/rules/tryceratops/mod.rs
33
---
4-
TRY302.py:12:5: TRY302 Remove exception handler; error is immediately re-raised
4+
TRY203.py:12:5: TRY203 Remove exception handler; error is immediately re-raised
55
|
66
10 | try:
77
11 | process()
88
12 | except Exception:
99
| _____^
1010
13 | | raise
11-
| |_____________^ TRY302
11+
| |_____________^ TRY203
1212
14 |
1313
15 | def bad():
1414
|
1515

16-
TRY302.py:18:5: TRY302 Remove exception handler; error is immediately re-raised
16+
TRY203.py:18:5: TRY203 Remove exception handler; error is immediately re-raised
1717
|
1818
16 | try:
1919
17 | process()
2020
18 | except Exception:
2121
| _____^
2222
19 | | raise
2323
20 | | print("this code is pointless!")
24-
| |________________________________________^ TRY302
24+
| |________________________________________^ TRY203
2525
21 |
2626
22 | def bad():
2727
|
2828

29-
TRY302.py:25:5: TRY302 Remove exception handler; error is immediately re-raised
29+
TRY203.py:25:5: TRY203 Remove exception handler; error is immediately re-raised
3030
|
3131
23 | try:
3232
24 | process()
3333
25 | except:
3434
| _____^
3535
26 | | # I am a comment, not a statement!
3636
27 | | raise
37-
| |_____________^ TRY302
37+
| |_____________^ TRY203
3838
28 |
3939
29 | def bad():
4040
|
4141

42-
TRY302.py:32:5: TRY302 Remove exception handler; error is immediately re-raised
42+
TRY203.py:32:5: TRY203 Remove exception handler; error is immediately re-raised
4343
|
4444
30 | try:
4545
31 | process()
4646
32 | except Exception:
4747
| _____^
4848
33 | | raise
49-
| |_____________^ TRY302
49+
| |_____________^ TRY203
5050
34 |
5151
35 | def bad():
5252
|
5353

54-
TRY302.py:38:5: TRY302 Remove exception handler; error is immediately re-raised
54+
TRY203.py:38:5: TRY203 Remove exception handler; error is immediately re-raised
5555
|
5656
36 | try:
5757
37 | process()
5858
38 | except Exception as e:
5959
| _____^
6060
39 | | raise
61-
| |_____________^ TRY302
61+
| |_____________^ TRY203
6262
40 |
6363
41 | def bad():
6464
|
6565

66-
TRY302.py:44:5: TRY302 Remove exception handler; error is immediately re-raised
66+
TRY203.py:44:5: TRY203 Remove exception handler; error is immediately re-raised
6767
|
6868
42 | try:
6969
43 | process()
7070
44 | except Exception as e:
7171
| _____^
7272
45 | | raise e
73-
| |_______________^ TRY302
73+
| |_______________^ TRY203
7474
46 |
7575
47 | def bad():
7676
|
7777

78-
TRY302.py:50:5: TRY302 Remove exception handler; error is immediately re-raised
78+
TRY203.py:50:5: TRY203 Remove exception handler; error is immediately re-raised
7979
|
8080
48 | try:
8181
49 | process()
8282
50 | except MyException:
8383
| _____^
8484
51 | | raise
85-
| |_____________^ TRY302
85+
| |_____________^ TRY203
8686
52 | except Exception:
8787
53 | raise
8888
|
8989

90-
TRY302.py:52:5: TRY302 Remove exception handler; error is immediately re-raised
90+
TRY203.py:52:5: TRY203 Remove exception handler; error is immediately re-raised
9191
|
9292
50 | except MyException:
9393
51 | raise
9494
52 | except Exception:
9595
| _____^
9696
53 | | raise
97-
| |_____________^ TRY302
97+
| |_____________^ TRY203
9898
54 |
9999
55 | def bad():
100100
|
101101

102-
TRY302.py:58:5: TRY302 Remove exception handler; error is immediately re-raised
102+
TRY203.py:58:5: TRY203 Remove exception handler; error is immediately re-raised
103103
|
104104
56 | try:
105105
57 | process()
106106
58 | except MyException as e:
107107
| _____^
108108
59 | | raise e
109-
| |_______________^ TRY302
109+
| |_______________^ TRY203
110110
60 | except Exception as e:
111111
61 | raise e
112112
|
113113

114-
TRY302.py:60:5: TRY302 Remove exception handler; error is immediately re-raised
114+
TRY203.py:60:5: TRY203 Remove exception handler; error is immediately re-raised
115115
|
116116
58 | except MyException as e:
117117
59 | raise e
118118
60 | except Exception as e:
119119
| _____^
120120
61 | | raise e
121-
| |_______________^ TRY302
121+
| |_______________^ TRY203
122122
62 |
123123
63 | def bad():
124124
|
125125

126-
TRY302.py:66:5: TRY302 Remove exception handler; error is immediately re-raised
126+
TRY203.py:66:5: TRY203 Remove exception handler; error is immediately re-raised
127127
|
128128
64 | try:
129129
65 | process()
130130
66 | except MyException as ex:
131131
| _____^
132132
67 | | raise ex
133-
| |________________^ TRY302
133+
| |________________^ TRY203
134134
68 | except Exception as e:
135135
69 | raise e
136136
|
137137

138-
TRY302.py:68:5: TRY302 Remove exception handler; error is immediately re-raised
138+
TRY203.py:68:5: TRY203 Remove exception handler; error is immediately re-raised
139139
|
140140
66 | except MyException as ex:
141141
67 | raise ex
142142
68 | except Exception as e:
143143
| _____^
144144
69 | | raise e
145-
| |_______________^ TRY302
145+
| |_______________^ TRY203
146146
70 |
147147
71 | def fine():
148148
|
149-
150-

ruff.schema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)