Skip to content

Commit 97afc70

Browse files
Remove preview gating for flake8-simplify rules (#9686)
## Summary Un-gates detecting `dict.get` rewrites in `if` expressions (rather than just `if` statements).
1 parent d90a420 commit 97afc70

4 files changed

+40
-207
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ mod tests {
5757
}
5858

5959
#[test_case(Rule::YodaConditions, Path::new("SIM300.py"))]
60-
#[test_case(Rule::IfElseBlockInsteadOfDictGet, Path::new("SIM401.py"))]
6160
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
6261
let snapshot = format!(
6362
"preview__{}_{}",

crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs

-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ pub(crate) fn if_exp_instead_of_dict_get(
224224
body: &Expr,
225225
orelse: &Expr,
226226
) {
227-
if checker.settings.preview.is_disabled() {
228-
return;
229-
}
230-
231227
let Expr::Compare(ast::ExprCompare {
232228
left: test_key,
233229
ops,

crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM401_SIM401.py.snap

+40
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,44 @@ SIM401.py:45:5: SIM401 [*] Use `vars[idx] = a_dict.get(key, "default")` instead
159159
50 47 | ###
160160
51 48 | # Negative cases
161161

162+
SIM401.py:123:7: SIM401 [*] Use `a_dict.get(key, "default3")` instead of an `if` block
163+
|
164+
122 | # SIM401
165+
123 | var = a_dict[key] if key in a_dict else "default3"
166+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM401
167+
124 |
168+
125 | # SIM401
169+
|
170+
= help: Replace with `a_dict.get(key, "default3")`
171+
172+
Unsafe fix
173+
120 120 | ###
174+
121 121 |
175+
122 122 | # SIM401
176+
123 |-var = a_dict[key] if key in a_dict else "default3"
177+
123 |+var = a_dict.get(key, "default3")
178+
124 124 |
179+
125 125 | # SIM401
180+
126 126 | var = "default-1" if key not in a_dict else a_dict[key]
181+
182+
SIM401.py:126:7: SIM401 [*] Use `a_dict.get(key, "default-1")` instead of an `if` block
183+
|
184+
125 | # SIM401
185+
126 | var = "default-1" if key not in a_dict else a_dict[key]
186+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM401
187+
127 |
188+
128 | # OK (default contains effect)
189+
|
190+
= help: Replace with `a_dict.get(key, "default-1")`
191+
192+
Unsafe fix
193+
123 123 | var = a_dict[key] if key in a_dict else "default3"
194+
124 124 |
195+
125 125 | # SIM401
196+
126 |-var = "default-1" if key not in a_dict else a_dict[key]
197+
126 |+var = a_dict.get(key, "default-1")
198+
127 127 |
199+
128 128 | # OK (default contains effect)
200+
129 129 | var = a_dict[key] if key in a_dict else val1 + val2
201+
162202

crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM401_SIM401.py.snap

-202
This file was deleted.

0 commit comments

Comments
 (0)